How do I search for an object by its ObjectId in the mongo console?

后端 未结 12 2616
心在旅途
心在旅途 2020-11-28 01:58

I\'ve found this question answered for C# and Perl, but not in the native interface. I thought this would work:

db.theColl.find( { _id: ObjectId(\"4ecbe7f9e8c

12条回答
  •  情话喂你
    2020-11-28 02:19

    If you're using Node.js:

    > var ObjectId = require('mongodb').ObjectId; 
    > var id = req.params.gonderi_id;       
    > var o_id = new ObjectId(id);
    > db.test.find({_id:o_id})
    

    Edit: corrected to new ObjectId(id), not new ObjectID(id)

提交回复
热议问题