Does Mongoose support the Mongodb `findAndModify` method?

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

    I would suggest using the direct command style shown at the bottom of http://www.mongodb.org/display/DOCS/findAndModify+Command. I'm not familiar enough with mongoose to know the method for running a command, but all drivers provide some way to do it. If mongoose doesn't, you can do it directly using the style described at the top of http://www.mongodb.org/display/DOCS/Commands.

    That said, you should make sure that you really need findAndModify and that update won't do what you need it to do. To see what update is capable of take a look at http://www.mongodb.org/display/DOCS/Updating.

提交回复
热议问题