- Data Models >
- Data Model Examples and Patterns >
- Model Specific Application Contexts >
- Model Data for Atomic Operations
Model Data for Atomic Operations¶
On this page
Pattern¶
Consider the following example that keeps a library book and its checkout information. The example illustrates how embedding fields related to an atomic update within the same document ensures that the fields are in sync.
Consider the following book
document that stores the number of
available copies for checkout and the current checkout information:
You can use the db.collection.findAndModify()
method to
atomically determine if a book is available for checkout and update
with the new checkout information. Embedding the available
field
and the checkout
field within the same document ensures that the
updates to these fields are in sync: