MongoDB - Atomic Operations

MongoDB does now not guide multi-report atomic transactions.

it does provide atomic operations on a unmarried record.

Model Data for Atomic Operations

The advocated method to hold atomicity would be to keep all the related facts, which is often updated together in a unmarried document using embedded files. Consider the subsequent merchandise report

    "product_name": "Google Pixel 3 Just Black 128",
    "category": "mobiles",
    "product_total": five,
    "product_available": three,
    "product_bought_by": [
            "customer": "David",
            "date": "4-Oct-2018"
            "customer": "Anderson",
            "date": "5-Oct-2018"

Here purchaser who buys the product within the product_bought_by discipline.Whenever a new purchaser buys the product, we will first test if the product is still to be had the usage of product_available discipline. But We can use findAndModify command for this capability because it searches and updates the report inside the identical pass.
findAndModify question makes sure that the product purchase data is updated only if it the product is available.

Welookups is optimized for learning.Copy right 2018 - 2019 kumar aditya singh .
All Right Reserved and you agree to have read and accepted our term and condition.
All Rights Reserved.