Created
April 3, 2014 14:08
-
-
Save adaptivedev/9955033 to your computer and use it in GitHub Desktop.
trying to use findAndModify from node.js to mongo: problem: no record inserted, null returned
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// no such record insert | |
> use test | |
switched to db test | |
> show collections | |
system.indexes | |
test | |
> db.test.find() | |
{ "_id" : ObjectId("533d5ec091d39080c18ec8ba"), "_accountId" : "100000057408993" } | |
> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
users.js: addUser: mongo example | |
'addUser: returns: null' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
exports.addUser = function(req, res) { | |
console.log("users.js: addUser: mongo example"); | |
var MongoClient = require('mongodb').MongoClient | |
, format = require('util').format; | |
MongoClient.connect('mongodb://127.0.0.1:27017/test', function(err, db) { | |
if(err) throw err; | |
db.collection('test').findAndModify({hello: 'world'}, [['_id','asc']], {$set: {hi: 'there'}}, {}, function(err, object) { | |
if (err) console.warn(err.message); | |
else console.dir("addUser: returns: " + object); // undefined if no matching object exists. | |
}); | |
}); | |
}; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment