It is not possible to refer to the methods on the Internet.
var ObjectId = require('mongodb').ObjectID;
let _id = ObjectId(_id);
this.collection.findOne({_id:_id}, {}, function(err, doc) {
console.log(err, doc);
});
I couldn’t find it after looking through the documents, mainly
"_id" : ObjectId("5927e105681b8b8fdb7887b9"),
The types may be different and cannot be queried. Please let me know if you know.
A classmate has asked this question, and it is the same as what you encountered;
var ObjectId = require('mongodb').ObjectID; //Does not work
var ObjectId = require('mongodb').ObjectId; //Work
Please refer to the official documentation.
Love MongoDB! Have fun!
Click Me <---Sign up and get a T-Shirt and other small gifts!
The 2017 MongoDB Chinese Community Beijing User Group Conference is coming soon, June 3, 2017 13:00-18:00