Querying a MongoDB based on Mongo ID in a node.js app

后端 未结 5 1160
夕颜
夕颜 2020-12-10 02:57

I\'m using a node.js and mongodb, and I\'m trying to query the database based on the mongo generated ID using the following:

    collection.findOne( {_id:doc         


        
5条回答
  •  死守一世寂寞
    2020-12-10 03:30

    The MongoDb is an object not a string. To convert my string I used:

        var id = require('mongodb').ObjectID(doc._id);
    

    This converts my string into a mongo ObjectId and matches the _id in the db!

提交回复
热议问题