如何解决如何只使用猫鼬删除用户发布的评论
Blockquote
delete( authenticate.verifyUser,(req,res,next) => {
Dishes.findById(req.params.dishId)
.then((dish) => {
if (dish != null && dish.comments.id(req.params.commentId) != null) {
if(dish.comments.author==req.user.id){
dish.comments.id(req.params.commentId).remove();
}
dish.save().then((dish) => {
Dishes.findById(dish._id)
.populate('comments.author')
.then((dish) => {
res.statusCode = 200;
res.setHeader('Content-Type','application/json');
res.json(dish);
})
},(err) => next(err));
当dish.comments.author.id等于req.user.id时,我想删除一条评论。我得到了req.user.id,但是我无法获得dish.comments.author。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。