在我的模型中,我有一个包含注释数组的线程。当我尝试更新这些评论时,它总是更新错误的一个,我无法弄清楚原因。
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})
}
})
此代码有效,但它始终更新第一条评论而非我尝试更新的评论。