dont need to pass value on upserts

v1.18.x
barisusakli 11 years ago
parent b0ec0f52a4
commit 035c32df66

@ -10,8 +10,8 @@ module.exports = function(db, module) {
if (!key) {
return callback();
}
data._key = key;
db.collection('objects').update({_key:key}, {$set:data}, {upsert:true, w: 1}, function(err) {
db.collection('objects').update({_key: key}, {$set: data}, {upsert: true, w: 1}, function(err) {
callback(err);
});
};
@ -27,7 +27,7 @@ module.exports = function(db, module) {
if (!key) {
return callback();
}
db.collection('objects').findOne({_key: key}, {_id:0, _key:0}, callback);
db.collection('objects').findOne({_key: key}, {_id: 0, _key: 0}, callback);
};
module.getObjects = function(keys, callback) {
@ -198,7 +198,7 @@ module.exports = function(db, module) {
field = helpers.fieldToString(field);
data[field] = value;
db.collection('objects').findAndModify({_key: key}, {}, {$inc: data}, {new:true, upsert:true}, function(err, result) {
db.collection('objects').findAndModify({_key: key}, {}, {$inc: data}, {new: true, upsert: true}, function(err, result) {
callback(err, result ? result[field] : null);
});
};

@ -15,12 +15,8 @@ module.exports = function(db, module) {
}
value = helpers.valueToString(value);
var data = {
score: parseInt(score, 10),
value: value
};
db.collection('objects').update({_key: key, value: value}, {$set: data}, {upsert:true, w: 1}, function(err) {
db.collection('objects').update({_key: key, value: value}, {$set: {score: parseInt(score, 10)}}, {upsert:true, w: 1}, function(err) {
callback(err);
});
};
@ -38,7 +34,7 @@ module.exports = function(db, module) {
var bulk = db.collection('objects').initializeUnorderedBulkOp();
for(var i=0; i<scores.length; ++i) {
bulk.find({_key: key, value: values[i]}).upsert().updateOne({$set: {score: scores[i], value: values[i]}});
bulk.find({_key: key, value: values[i]}).upsert().updateOne({$set: {score: scores[i]}});
}
bulk.execute(function(err, result) {
@ -52,15 +48,11 @@ module.exports = function(db, module) {
return callback();
}
value = helpers.valueToString(value);
var data = {
score: parseInt(score, 10),
value: value
};
var bulk = db.collection('objects').initializeUnorderedBulkOp();
for(var i=0; i<keys.length; ++i) {
bulk.find({_key: keys[i], value: value}).upsert().updateOne({$set: data});
bulk.find({_key: keys[i], value: value}).upsert().updateOne({$set: {score: parseInt(score, 10)}});
}
bulk.execute(function(err, result) {

Loading…
Cancel
Save