Does Mongoose support the Mongodb `findAndModify` method?

前端 未结 9 2168
[愿得一人]
[愿得一人] 2020-11-29 23:57

I would like to use findAndModify to atomically increment a field, using Mongoose.

However, the code below throws the error \"TypeError: Object # has no method \'fin

9条回答
  •  星月不相逢
    2020-11-30 00:44

    a lot of answers but I find this simple solution.

    Counter.findByIdAndUpdate(ID, {$inc: {next:1}}, function (err, data) {
    
    
    });
    

提交回复
热议问题