node.js mongodb select document by _id node-mongodb-native

后端 未结 10 1580
死守一世寂寞
死守一世寂寞 2020-12-02 08:28

I\'m trying to select a document by id

I\'ve tried:

collection.update({ \"_id\": { \"$oid\": + theidID } }

collection.update({ \"_id\": theidID }

c         


        
10条回答
  •  悲&欢浪女
    2020-12-02 08:43

    If you use Mongosee, you can simplify the function

    FindById:

    this replace in mongodb: "_id" : ObjectId("xyadsdd434434343"),

    example:
    
    // find adventure by id and execute
    Adventure.findById('xyadsdd434434343', function (err, adventure) {});
    

    https://mongoosejs.com/docs/api.html#model_Model.findById

提交回复
热议问题