如何在mongo的交易中实现回滚? [英] How to achieve rollback in transactions in mongo?
问题描述
在nodejs express服务器的请求和响应中,通常需要通过mongoose对mongodb进行查询。
在许多情况下,如果首先有几个查询执行成功,并且在一个事务处理中都会失败,那么可能会发生。
现在我需要回滚我的db状态到db的初始状态。
那么我怎么能在mongodb中有效地回滚?
请提供一些合适的参考。
我同意Hector。如果您需要多个文档交易,那么Mongo可能不适合您。您可以将数据结构嵌入到单个文档中吗?那么你可以得到你正在寻找的回滚。
另一个选项是查看跨多个文档提供事务的Mongo克隆TokuMX。
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.
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.
这篇关于如何在mongo的交易中实现回滚?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!