Question

I had a discussion with a friend about MongoDb and it's atomicity, and I'd like know if he's right.. I was told, that MongoDb during an update does two atomic operations:

  • it's deleting the existing document (first atomic operation);
  • and inserting a new one (second atomic operation).

Which means that for a fraction of the time, the document is empty.

Even though this doesn't sound plausible to me, does anyone know for sure if this is true or not true?

Thanks a lot for you responses and would appreciate if someone could point to some online documents to read about it.

Edit: spelling

Was it helpful?

Solution

MongoDB uses a global write lock (per server before 2.2 and per database in 2.2) for all mutating operations. This means that regardless of the implementation details of updates they are atomic from the perspective of clients. The global write lock guarantees that no other client can see a partial update to a single document.

There is documentation on MongoDB's global write lock here: http://www.mongodb.org/display/DOCS/How+does+concurrency+work

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top