MongoDB Multi-Statement Transactions? Yes We Can!

April 3, 2013
Author
Zardosht.Kasheff
Share this Post:

Earlier, I talked about the transactional semantics we are introducing to MongoDB. As I hinted at the end of the post, we are actually doing more. We are introducing multi-statement transactions. That’s right, multiple queries, updates, deletes, and inserts will be able to run inside of a single transaction. We are working on the details of the semantics as we develop our beta, but at a high level, think of it as having the same semantics as TokuDB and InnoDB’s multi-statement transactions in MySQL.

So how will it work? We introduce three new commands:

This begins a transaction with the isolation level of MVCC, which means queries will use a snapshot of the system. This is essentially the same as “repeatable-read” in MySQL. Isolations of “serializable” and “readUncommitted” will be supported

These commands either commit the transaction or rollback the transaction.

Here is a screenshot of a transaction that I started and rolled back.

Transactions will operate over a single connection. That is, after a “beginTransaction” command has been applied over a connection, all work on that connection will belong to a single transaction until that same connection sends a commit or rollback command. So, any driver that uses a pool of connections to handle requests must be careful using multi-statement transactions. We have yet to investigate drivers to see what it would take for them to work with this model. We expect some to just work, and others to require care or changes.

Do you want to participate in the process of bringing full transactions to MongoDB? We’re looking for MongoDB experts to test our build on your real-world workloads. Evaluator feedback will be used in creating the product road map. Please email me at [email protected] if interested.

Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments

Far
Enough.

Said no pioneer ever.
MySQL, PostgreSQL, InnoDB, MariaDB, MongoDB and Kubernetes are trademarks for their respective owners.
© 2026 Percona All Rights Reserved