Mongoose Convert String to ObjectId

If you want to get datas from MongoDb by Id, you cannot use the string directly.

You need to convert the string to ObjectId. After doing this, you can use findOne() or findById() functions.

[js]
var mongoose = require(‘mongoose’);
var id = mongoose.Types.ObjectId(‘4edd40c86762e0fb12000003’);
[/js]