Last active
November 29, 2015 02:38
-
-
Save sethblanchard/78ba49e4904c7f94db8d to your computer and use it in GitHub Desktop.
Node Replace
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
var mongo = require('mongoskin'); | |
var db = mongo.db("mongodb://localhost/learnmongo"); | |
db.bind('sample'); | |
var test1 = { | |
first: 'Jane', | |
last: 'Doe', | |
sex: 'female' | |
} | |
var test2 = { | |
first: 'John', | |
last: 'Doe', | |
sex: 'male' | |
} | |
db.sample.insert(test1, function(err, result){ | |
console.log('=== Initial Result ==='); | |
console.log(err, result); | |
var objId = mongo.helper.toObjectID(result.ops[0]._id) | |
db.sample.replaceOne( | |
{_id: objId}, | |
test2, | |
{upsert: false}, | |
function(err, rslt){ | |
console.log('=== Update Result ==='); | |
console.log(err, rslt.result); | |
return; | |
} | |
); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This returns
Why doesn't the second record replace the first record? What am I missing