router.delete('/api/comment', (req, res, next) => {
const { _id, postID } = req.body;
commentModel.remove({ _id }, (err, doc) => {
if (err) {
res.json({ code: 1, msg: err });
} else {
// 更新文章的comments列表
postModel.update({ _id: postID }, { $pull: { comments: _id } }, (err, postDoc) => {
res.json({ code: 0, data: doc });
});
}
});
});文章里面存了一個評論_id組成的數組comments刪除評論成功,但是更新文章的comments列表失敗$push都是可以的,不知道為什么$pull不行?沒有報錯,返回{ nModified: 0, ok: 1 }
mongoose 操作數組
嗶嗶one
2018-08-10 13:38:31