From 610d45bb32f784c5f17b883fde83cd045e24349b Mon Sep 17 00:00:00 2001 From: Baris Soner Usakli Date: Tue, 3 Dec 2013 17:29:10 -0500 Subject: [PATCH] completed hashes in mongodb I hope :) --- src/database/mongo.js | 14 ++++++++++---- src/routes/debug.js | 11 ++++++++++- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/database/mongo.js b/src/database/mongo.js index 571a7b33da..a202a63cea 100644 --- a/src/database/mongo.js +++ b/src/database/mongo.js @@ -163,21 +163,27 @@ var data = {}; data[field] = ""; db.collection('objects').update({_key:key}, {$unset : data}, function(err, result) { - console.log(err, result); callback(err, result); }); } module.incrObjectField = function(key, field, callback) { - throw new Error('not-implemented'); + module.incrObjectFieldBy(key, field, 1, callback); } module.decrObjectField = function(key, field, callback) { - throw new Error('not-implemented'); + module.incrObjectFieldBy(key, field, -1, callback); } module.incrObjectFieldBy = function(key, field, value, callback) { - throw new Error('not-implemented'); + var data = {}; + data[field] = value; + db.collection('objects').update({_key:key}, {$inc : data}, function(err, result) { + console.log('incrObjectFieldBy', err, result); + module.getObjectField(key, field, function(err, value) { + callback(err, value); + }); + }); } diff --git a/src/routes/debug.js b/src/routes/debug.js index eec77f3402..ac183d0b72 100644 --- a/src/routes/debug.js +++ b/src/routes/debug.js @@ -141,6 +141,13 @@ var DebugRoute = function(app) { }); } + function incrObjectFieldBy(callback) { + db.incrObjectFieldBy(objectKey, 'age', 3, function(err, data) { + console.log('incrObjectFieldBy return', data); + callback(err, {'incrObjectFieldBy':data}); + }); + } + var tasks = [ setObject, getObject, @@ -153,7 +160,9 @@ var DebugRoute = function(app) { getObjectField, getObjectFields, getObjectValues, - isObjectField + isObjectField, + incrObjectFieldBy, + getObject ]; require('async').series(tasks, function(err, results) {