lobengula3rd
lobengula3rd

Reputation: 1851

is mongo.update() gets an immediate write lock?

I am trying to understand if issuing a mongo.update call will take a write lock immediately, or will it first take a read lock to get the data and only then will take a write lock to modify the data.

Also i am trying to understand what will be the behaviour when using other mongo functions like findOneAndUpdate or findAndModify

Upvotes: 1

Views: 154

Answers (1)

Alex
Alex

Reputation: 21766

According to the documentation, when modifying a single document, both findAndModify and the update method atomically update the document. This implies that a write lock is taken out immediately. If you want to atomically update multiple records you have to use the $isolated operator.

Upvotes: 1

Related Questions