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。