Find with _id not working in mongodb

前端 未结 1 1175
半阙折子戏
半阙折子戏 2021-01-27 00:00

I have a collection named Releases that holds a subdocument named product. My collection looks like this:

{
 \"_id\": ObjectId(\"5b1010e4ef2afa6e5edea0c2\"),
  \         


        
1条回答
  •  醉梦人生
    2021-01-27 00:22

    You need to change your id from string to mongoose objectId

    var id = req.body.productId
       var query = {'product._id' : mongoose.Types.ObjectId(req.body.productId)};
       Release.find(query)
       .select('_id version description product releasedate')
       .sort({releasedate: 1 })
       .exec()
       .then(releases => {
         console.log(releases);
         res.status(200).json(releases);
       })
    

    0 讨论(0)
提交回复
热议问题