“原子截面”在 Ruby MongoDB 驱动程序中?

发布于 2024-10-03 11:00:50 字数 79 浏览 0 评论 0原文

有没有办法在 MongoDB 服务器上(使用 Ruby 驱动程序)将一组非原子操作作为单个原子操作执行?我需要的基本上是对某些对象/集合的锁定。

Is there a way to perform a set of non-atomic actions on MongoDB server (using the Ruby driver) as an single atomic action? What I need is basically a lock on certain object/collection.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

最丧也最甜 2024-10-10 11:00:50

由于您可以对单个文档执行原子操作,因此有多种方法可以模拟您想要的操作。请参阅这篇文章:

http://kylebanker.com/blog/2010/ 06/07/mongodb-inventory-transactions/

有关该想法背后的一些原则,请参阅以下内容:

http://www.eaipatterns.com/docs/IEEE_Software_Design_2PC.pdf

Because you can perform atomic operations on single documents, there are ways to simulate what you want. See this article:

http://kylebanker.com/blog/2010/06/07/mongodb-inventory-transactions/

And for some of the principles behind the ideas there, see this one:

http://www.eaipatterns.com/docs/IEEE_Software_Design_2PC.pdf

吃颗糖壮壮胆 2024-10-10 11:00:50

在 Ruby 驱动程序中无法做到这一点,因为在 MongoDB 中也无法做到这一点。 Mongo仅支持单文档原子操作。因此基本上单个文档的插入、更新或删除是原子完成的,但不是跨多个文档的操作。

如果发生错误,您可以通过尝试手动“回滚”来伪造交易。在这种情况下,回滚是将所有更改替换为之前的值。但这需要手动操作,并且没有大多数 SQL 服务器提供的 ACID 保证。

There's no way to do it in the Ruby driver because there's no way to do it in MongoDB. Mongo only supports single-document atomic operations. So basically an insert, update or delete of a single document is done atomically, but not operations across multiple documents.

You might be able to fake a transaction by attempting a manual "roll-back" if an error occurs. A roll-back in this case would be to replace any changes with the previous values. But that's going to manual and not have the ACID guarantees that you would get from most SQL servers.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文