问题
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.
回答1:
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.
回答2:
Going through mongo tutorials
Here is a link i found for making two phase commits ( may be it is not guaranteed ) :
http://docs.mongodb.org/manual/tutorial/perform-two-phase-commits/
回答3:
There is no support for traditional ACID database transactions in MongoDB regardless of what you put on top of it. This is not an issue with Mongoose or Express.js, it's a characteristic of MongoDB.
MongoDB supports atomic operations which means that saving to a collection is guaranteed to succeed completely or fail, in other words you won't get partial updates to a single document in a collection. But there is no support for multi-updates in a single transaction.
http://docs.mongodb.org/manual/faq/fundamentals/#does-mongodb-support-transactions
来源:https://stackoverflow.com/questions/21487233/how-to-achieve-rollback-in-transactions-in-mongo