0

我有以下代码:

var conditions = {_id: playerID, 'gameStats.GameID' : gameID},
    update = {$inc: {'gameStats.$.wins' : 1}},
    options = {new : true};

player.findAndModify(conditions, update, options, function (err, doc) {
    if (err) { 
        console.log("updated failed")
        return res.sendStatus(300);     
}

当我执行它时,返回错误消息“TypeError:undefined is not a function”,我真的无法弄清楚问题出在哪里。有人可以帮忙吗?

4

1 回答 1

1

问题是您使用的是“猫鼬”并且没有.findAndModify()方法。改用.findOneAndUpdate()

player.findOneAndUpdate(conditions, update, options, function (err, doc) {
    if (err) { 
        console.log("updated failed")
        res.sendStatus(300);     
    } else {
      // do things that are happy with the response
    }
});
于 2015-08-20T10:20:04.203 回答