MongoDB - Atomic Operations

Model Data for Atomic Operations

The recommended approach to maintain atomicity would be to keep all the related information, which is frequently updated together in a single document using embedded documents.
Consider the following products document

Here customer who buys the product in the product_bought_by field.whenever a new customer buys the product, we will first check if the product is still available using product_available field.
But We can use findAndModify command for this functionality because it searches and updates the document in the same go.