I have a method to find a document in my database based on its ObjectID:
console.log(\'id: \' + id + \' type: \' + typeof id); collection.findOne
Try this:
var hex = /[0-9A-Fa-f]{6}/g; id = (hex.test(id))? ObjectId(id) : id; collection.findOne({'_id':new ObjectID(id)}, function(error,doc) { if (error) { callback(error); } else { callback(null, doc); } });