MongoDB is relaxing many of the typical Atomicity, Consistency, Isolation and Durability (ACID) constraints found in RDBMS. In the absence of transactions, it can sometimes be difficult to keep the state consistent across operations, especially in the event of failures.
Luckily, some operations are atomic at the document level:
- update()
- findandmodify()
- remove()
These are all atomic (all or nothing) for a single document.
This means that, if we embed information in the same document, we can make sure they are always in sync.
An example would be an inventory application, with a document per item in our inventory, where we would need to total the available items left in stock how many have been placed in a shopping cart in sync, and use this data to sum up the total available items.
With total_available = 5, available_now = 3, shopping_cart_count...