What did MongoDB not being ACID compliant before v4 really mean?

前端 未结 10 1100
情书的邮戳
情书的邮戳 2020-12-04 04:15

I am not a database expert and have no formal computer science background, so bear with me. I want to know the kinds of real world negative things that can happen

相关标签:
10条回答
  • 2020-12-04 05:12

    "In MongoDB, an operation on a single document is atomic" - That's the thing for past

    In the new version of MongoDB 4.0 you CAN :

    However, for situations that require atomicity for updates to multiple documents or consistency between reads to multiple documents, MongoDB provides the ability to perform multi-document transactions against replica sets. Multi-document transactions can be used across multiple operations, collections, databases, and documents. Multi-document transactions provide an “all-or-nothing” proposition. When a transaction commits, all data changes made in the transaction are saved. If any operation in the transaction fails, the transaction aborts and all data changes made in the transaction are discarded without ever becoming visible. Until a transaction commits, no write operations in the transaction are visible outside the transaction.

    Though there are few limitations for How and What operations can be performed.

    Check the Mongo Doc. https://docs.mongodb.com/master/core/transactions/

    0 讨论(0)
  • 2020-12-04 05:15

    I think other people gave good answers already. However i would like to add that there are ACID NOSQL DBs (like http://ravendb.net/ ). So it is not only decision NOSQL - no ACID vs Relational with ACID....

    0 讨论(0)
  • 2020-12-04 05:15

    "won't save correctly" could mean:

    1. By default MongoDB does not save your changes to the drive immediately. So there is a possibility that you tell a user "update is successful", power outage happens and the update is lost. MongoDB provides options to control level of update "durability". It can wait for the other replica(s) to receive this update (in memory), wait for the write to happen to the local journal file, etc.

    2. There is no easy "atomic" updates to multiple collections and even multiple documents in the same collection. It's not a problem in most cases because it can be circumvented with Two Phase Commit, or restructuring your schema so updates are made to a single document. See this question: Document Databases: Redundant data, references, etc. (MongoDB specifically)

    0 讨论(0)
  • 2020-12-04 05:18

    As of MongoDB v4.0, multi-document ACID transactions are to be supported. Through snapshot isolation, transactions will provide a globally consistent view of data, and enforce all-or-nothing execution to maintain data integrity.

    They feel like transactions from the relational world, e.g.:

    with client.start_session() as s:
        s.start_transaction()
        try:
            collection.insert_one(doc1, session=s)
            collection.insert_one(doc2, session=s)
            s.commit_transaction()
        except Exception:
            s.abort_transaction()
    

    See https://www.mongodb.com/blog/post/multi-document-transactions-in-mongodb

    0 讨论(0)
提交回复
热议问题