Mongoose无法更新我的文档

时间:2015-07-21 12:51:48

标签: node.js mongodb express mongoose

我需要将feedback批量删除到articlecommentreply实体。这是我的实现

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"})

我的代码有什么问题?

1 个答案:

答案 0 :(得分:3)

您将status属性视为两者一个字符串(将其设置为deleted一个对象(通过设置两个属性) ,deletedBydeletedDate),这没有意义。