Why doesn't MongoDB have transactions? (pre-v4.0)

mongodb, transactions

Solution

Having no transaction is a trade-off to allow MongoDB to be scalable.

The purpose of a transaction is to make sure that the whole database stays consistent while multiple operations take place. But in contrary to most relational databases, MongoDB isn't designed to run on a single host. It is designed to be set up as a cluster of multiple shards where each shard is a replica-sets of multiple servers (optionally at different geographical locations).

A transaction can potentially affect lots of hosts of the database. That means that the transaction would have to be synchronized between all of these hosts. This would mean quite a lot of overhead and would scale very badly when increasing the size of the database by adding more servers.

The MongoDB FAQ explains it like this:

MongoDB does not have support for traditional locking or complex transactions with rollback. MongoDB aims to be lightweight, fast, and predictable in its performance. This is similar to the MySQL MyISAM autocommit model. By keeping transaction support extremely simple, MongoDB can provide greater performance especially for partitioned or replicated systems with a number of database server processes.

Problem

Update: MongoDB supports transactions from version 4.0. Original question: As far as I know, MongoDB doesn't support transactions, and there are no plans for implementing such support. What is the reason for this?

Original source