Manoj Chandramohan
Manoj Chandramohan

Reputation: 69

Concurrent partial updates in Mongo collection

Consider the following mongo document

{
  _id:...
  param1:oldValue1
  param2:oldValue2 
}

Suppose if am trying to do two concurrent partial updates with the following queries:

db.collection.update(  { _id:...} , { $set: { param1 : "newValue1"  } }
db.collection.update(  { _id:...} , { $set: { param2 : "newValue2"  } }

Will I get the following docuemnt state in mongo after these concurrent partial updates:

{
  _id:...
  param1:newValue1
  param2:newValue2
}

Does two concurrent updates leave the document with updated values considering the fact that the concurrent updates dont have common fields.without concurrent modification issue?

Upvotes: 1

Views: 526

Answers (1)

JohnnyHK
JohnnyHK

Reputation: 311835

Yes, regardless of the execution order of the two updates, the doc will end up as you show it. This is because the two atomic $set operations target distinct fields, and any field not referenced in the update isn't modified.

Upvotes: 1

Related Questions