How to achieve rollback in transactions in mongo?

express, mongodb, mongoose, node.js, transactions

Solution

I agree with Hector. If you need multiple document transactions then Mongo might not be a good fit for you. Can you embed your data structure in a single document? Then you can get the rollback you are looking for.

Another option is to look at the Mongo clone TokuMX which provides transactions across multiple documents.

Problem

I am using mongoose over mongodb. In a request and response from nodejs express server, generally requires a no of queries to mongodb through mongoose. In many cases it may happen, if first a few queries executes successfully and rest all failed under a transaction. Now i need to rollback my db state to the very initial state of db. So how can i rollback efficiently in mongodb? Please provide some suitable references.

Original source