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

后端 未结 10 1594
死守一世寂寞
死守一世寂寞 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:53

    With native_parser:false:

    var BSON = require('mongodb').BSONPure;
    var o_id = BSON.ObjectID.createFromHexString(theidID);
    

    With native_parser:true:

    var BSON = require('mongodb').BSONNative;
    var o_id = BSON.ObjectID.createFromHexString(theidID);
    

提交回复
热议问题