How to query based on _id in nodejs mongodb
大家讲道理
大家讲道理 2017-05-31 10:35:57
0
1
831

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.

大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

reply all(1)
曾经蜡笔没有小新

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

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template