I have a method to find a document in my database based on its ObjectID:
console.log(\'id: \' + id + \' type: \' + typeof id); collection.findOne
In my case, this worked:
var myId = JSON.parse(req.body.id); collection.findOne({'_id': ObjectID(myId)}, function(error,doc) { if (error) { callback(error); } else { callback(null, doc); } });
Don't forget to include at the beginning:
var ObjectId = require('mongodb').ObjectID;