From dedf4add534ececf7e8370258683662396977d64 Mon Sep 17 00:00:00 2001 From: Baris Soner Usakli Date: Thu, 6 Feb 2014 00:00:21 -0500 Subject: [PATCH] better incr for mongo --- src/database/mongo.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/database/mongo.js b/src/database/mongo.js index 9ebc45bd33..86384575bc 100644 --- a/src/database/mongo.js +++ b/src/database/mongo.js @@ -415,12 +415,11 @@ } field = field.replace(/\./g, '\uff0E'); data[field] = value; - db.collection('objects').update({_key:key}, {$inc : data}, {upsert:true}, function(err, result) { - module.getObjectField(key, field, function(err, value) { - if(callback) { - callback(err, value); - } - }); + + db.collection('objects').findAndModify({_key:key}, {}, {$inc: data}, {new:true, upsert:true}, function(err, result) { + if(callback) { + callback(err, result ? result[field] : null); + } }); }