Does Mongoose support the Mongodb `findAndModify` method?

前端 未结 9 2145
[愿得一人]
[愿得一人] 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:28

    This is fully supported in Mongoose 3.x now, though the name is slightly different.

    http://mongoosejs.com/docs/api.html#model_Model.findOneAndUpdate

    http://mongoosejs.com/docs/api.html#model_Model.findByIdAndUpdate

    http://mongoosejs.com/docs/api.html#model_Model.findOneAndRemove

    http://mongoosejs.com/docs/api.html#model_Model.findByIdAndRemove

提交回复
热议问题