MongoDB transactions? MongoDB transactions? mongodb mongodb

MongoDB transactions?


MongoDB doesn't support complex multi-document transactions. If that is something you absolutely need it probably isn't a great fit for you.

In most cases, however, we've found that complex transactions aren't a requirement. All operations in MongoDB are atomic on a single document, and we support nice update modifiers, which make a lot of operations that would need a transaction easy to implement (and fast).


That is true that MongoDB does't support transaction out of the box, but you can implement optimistic transactions on your own. They fit fine the unit of work. I wrote an java example and some explanation on a GitHub so you can easily repeat in C#.


As of v4.0, MongoDB supports multi-document ACID transactions. Through snapshot isolation, transactions provide a globally consistent view of data, and enforce all-or-nothing execution to maintain data integrity. For more info, see https://www.mongodb.com/transactions

In 4.2, MongoDB will also support sharded transactions.

In this blog post, I also outline our journey to multi-document ACID transactions, in case if you are interested in the history and our reasoning.