MongoDB achieves distributed ACID compliance through multi-document transactions using snapshot isolation, two-phase commit across shards, and majority write concern for durability.
MongoDB achieves ACID (Atomicity, Consistency, Isolation, Durability) compliance across multiple documents through multi-document transactions, introduced in version 4.0 for replica sets and extended to sharded clusters in version 4.2. These transactions provide snapshot isolation, ensuring all read operations within a transaction see a consistent view of data across multiple documents, even in distributed environments.
Snapshot isolation: Transactions read from a consistent snapshot taken at the start, preventing dirty reads and ensuring repeatable reads across nodes
Two-phase commit: For sharded clusters, a coordinator ensures all participating shards commit or abort together
Majority write concern: With { w: 'majority' }, writes are durable across most nodes, preventing data loss during failures
Write conflict detection: Transactions automatically abort on write conflicts, and drivers support transparent retry logic