How to achieve rollback in transactions in mongo? [closed]

二次信任 提交于 2019-12-18 14:53:16

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!