如何在mongo中实现事务回滚? [英] How to achieve rollback in transactions in mongo?

查看:22
本文介绍了如何在mongo中实现事务回滚?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 mongoose 而不是 mongodb.

I am using mongoose over mongodb.

在来自 nodejs express 服务器的请求和响应中,通常不需要通过 mongoose 向 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.

现在我需要将我的 db 状态回滚到 db 的初始状态.

Now i need to rollback my db state to the very initial state of db.

那么如何在 mongodb 中高效回滚?请提供一些合适的参考资料.

So how can i rollback efficiently in mongodb? Please provide some suitable references.

推荐答案

我同意 Hector 的观点.如果您需要多个文档事务,那么 Mongo 可能不适合您.您可以将数据结构嵌入到单个文档中吗?然后你就可以得到你正在寻找的回滚.

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.

另一种选择是查看提供跨多个文档的事务的 Mongo 克隆 TokuMX.

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

这篇关于如何在mongo中实现事务回滚?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆