How does nodejs mongodb query based on _id

  mongodb, question

Nor can we refer to what we have done online.

var ObjectId = require('mongodb').ObjectID;
 let _id = ObjectId(_id);
 this.collection.findOne({_id:_id}, {}, function(err, doc) {
 console.log(err, doc);

I looked through the documents and couldn’t find them, mainly

"_id" : ObjectId("5927e105681b8b8fdb7887b9"),

It may be of different types and cannot be queried. Please let me know if you know.

This question has been asked by some classmates and is the same as what you have encountered.

var ObjectId = require(‘mongodb’).ObjectID; //Does not work

var ObjectId = require(‘mongodb’).ObjectId; //Work

Refer to official documents more often.

Love MongoDB! Have fun!

Click Me<-sign up and give small gifts such as T Shirt!

The 2017MongoDB Chinese Community Beijing User Group Conference is approaching, June 3, 2017, 13: 00-18: 00