What's the difference between findAndModify and update in MongoDB?

后端 未结 5 1308
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-27 10:09

I\'m a little bit confused by the findAndModify method in MongoDB. What\'s the advantage of it over the update method? For me, it seems that it jus

5条回答
  •  没有蜡笔的小新
    2020-11-27 10:45

    findAndModify returns the document, update does not.

    If I understood Dwight Merriman (one of the original authors of mongoDB) correctly, using update to modify a single document i.e.("multi":false} is also atomic. Currently, it should also be faster than doing the equivalent update using findAndModify.

提交回复
热议问题