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 に答える