From 10474f8e2a75d4bc4fcc511bcb6bf271abdf7b0f Mon Sep 17 00:00:00 2001 From: Baris Usakli Date: Tue, 3 Dec 2013 15:17:42 -0500 Subject: [PATCH] more mongo work --- src/database/mongo.js | 33 ++++++++++++++++++------ src/routes/debug.js | 60 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+), 8 deletions(-) diff --git a/src/database/mongo.js b/src/database/mongo.js index 801abb6dd7..d0768ccba7 100644 --- a/src/database/mongo.js +++ b/src/database/mongo.js @@ -32,6 +32,7 @@ db.createCollection('sets', function(err, collection) { }); + callback(err); }); // look up how its done in mongo @@ -74,20 +75,27 @@ //hashes module.setObject = function(key, data, callback) { + console.log('SET OBJECT CALLED', key, data); data['_key'] = key; - db.collection('objects').insert(data, {w:1}, function(err, result) { + db.collection('objects').update({_key:key}, {$set:data}, {upsert:true, w: 1}, function(err, result) { + console.log('SET OBJECT COMPLETE', err, result); callback(err, result); }); } module.setObjectField = function(key, field, value, callback) { - db.collection('objects').update(); + var data = {}; + data[field] = value; + db.collection('objects').update({_key:key}, {$set:data}, {upsert:true, w: 1}, function(err, result) { + console.log('SET OBJECT COMPLETE', err, result); + callback(err, result); + }); } module.getObject = function(key, callback) { - console.log('calling findOne'); + console.log('GET OBJECT', key); db.collection('objects').findOne({_key:key}, function(err, item) { - console.log(item); + console.log('RETURNING OBJECT', item); callback(err, item); }); } @@ -106,7 +114,7 @@ var _fields = {}; for(var i=0; i