我需要将feedback
批量删除到article
,comment
或reply
实体。这是我的实现
exports.batchDeleteFeedback = function(req, res, next) {
var articleId = req.body.articleId
var commentId = req.body.commentId
var replyId = req.body.replyId
var Target, targetId, field
if (articleId) {
Target = Article
targetId = articleId
field = 'article'
}
else if (commentId) {
Target = Comment
targetId = commentId
field = 'comment'
}
else if (replyId) {
Target = Reply
targetId = replyId
field = 'reply'
}
var criteria = {}
criteria['target.' + field] = targetId
Feedback.update(criteria, {$set: {
'status': 'deleted'
,'status.deletedBy': req.user
,'status.deletedDate': new Date
}}, {multi: true}, function(err) {
if (err)
return next(err)
Target.findById(targetId).exec(function(err, target) {
if (err)
return next(err)
var json = target.toJSON()
json.success = 'success batch delete feedbacks'
return res.json(json)
})
})
}
我收到此错误消息
cannot use the part (status of status.deletedBy) to traverse the element ({status: "deleted"})
我的代码有什么问题?
答案 0 :(得分:3)
您将status
属性视为两者一个字符串(将其设置为deleted
)和一个对象(通过设置两个属性) ,deletedBy
和deletedDate
),这没有意义。