Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

is mongo update ($set) on a single document atomic

Tags:

mongodb

I have a code similar to

db.myColletion.update({'_id':ObjectId("...")}, {'$set': {'state': 'CA'}})

Is above an atomic operation?

Do I need to use findAndModify even on single document for atomicity??

like image 425
GJain Avatar asked May 31 '14 21:05

GJain


1 Answers

Yes, all write operations with MongoDB are atomic at the level of a single document.

The key difference between update and findAnyModify is that the latter also provides you with the original or updated document.

like image 67
JohnnyHK Avatar answered Sep 21 '22 15:09

JohnnyHK