Mongoose findOneAndUpdate更新错误的项目

时间:2018-02-14 01:17:36

标签: mongodb mongoose

在我的模型中,我有一个包含注释数组的线程。当我尝试更新这些评论时,它总是更新错误的一个,我无法弄清楚原因。

        Thread.findOneAndUpdate({
          'comments._id': req.params.commentId, 
          'comments.created_by.user_id': user._id
        }, 
        { 
          $set: {
            'comments.$.content': req.body.content,
          }
        }, { new: true }, (err, thread) => {
         if(!err && thread){
            res.status(200).json({success: true})
          }
        })

此代码有效,但它始终更新第一条评论而非我尝试更新的评论。

0 个答案:

没有答案