Correct way to search for MongoDB entries by '_id' in Node

后端 未结 5 1778
野趣味
野趣味 2021-02-03 17:35

I\'m using MongoDb (as part of MongoJS) in Node. Here is the documentation for MongoJS.

I\'m trying to do a call within Node based

5条回答
  •  故里飘歌
    2021-02-03 18:16

    If you are using MongoJS, you can do:

    var ObjectId = mongojs.ObjectId;
    

    Then,

    db.users.find({"_id": ObjectId(id)}, function(err, user){...}
    

提交回复
热议问题