Correct way to search for MongoDB entries by '_id' in Node
You need to require the ObjectId function before using it:
var ObjectId = require('mongodb').ObjectID;
If you are using MongoJS, you can do:
var ObjectId = mongojs.ObjectId;
Then,
db.users.find({"_id": ObjectId(id)}, function(err, user){...}
if you are using mongoose you can try this:
var mongoose = require('mongoose')
usersSchema = mongoose.model('users'),
mongoose.Types.ObjectId("<object_id>")
usersSchema.find({"_id": mongoose.Types.ObjectId("<object_id>")}, function (err, record) {
// Do stuff
});