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.

10 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
A. Jesse Jiryu Davis

Hi. Most drivers have features to pin the current thread to a socket in the driver’s pool, with a method called requestStart() or start_request() depending on the language. More info for the Python driver here:

http://emptysquare.net/blog/requests-in-python-and-mongodb/

We need this for other sequences of commands that require a single connection, like authenticate or copyDatabase.

How do you intend to support transactions in a sharded cluster? And are operations done in a transaction visible on replica-set secondaries before they’re committed?

Deepak

I have created a tree structure in mongodb (which is not much in size), now i m searching 1mn record sequentially, on mongodb tree and updates as well which is taking more then 5 hour or single node cluster.How should i do it so that will become fast, also please suggest me that, does making more node cluster make it fast. Also i make a connection to same mongod –port 270217 does it distribute processing across to the cluster or not ?

Samuel

These new and shiny transactions can be nested?

So, can you run something like this?


begin transaction // 0
insert
begin transaction // 1
insert
rollback // 1 - remove second insert
commit // 0 - will persist first insert

manoj tailor

this commands not working in MongoDB version 3.0.1. I tested it and the result is
db.runCommand({‘rollbackTransaction’:1})

“ok” : 0,
“errmsg” : “no such command: rollbackTransaction”,
“code” : 59,
“bad cmd” : {
“rollbackTransaction” : 1
}

On which version of MongoDB this commands are available?

iliadis

I got same problem, is it any answer it

Max

Lo solucionaron ?

Harsh Jain

Hi,

I tried this thing on my MonodDB 2.6 driver and its not working giving error. Does it work on some specific drivers. Can u please tell us which drivers does it support. ??