0

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

4

2 回答 2

1

因为您可以对单个文档执行原子操作,所以有多种方法可以模拟您想要的。见这篇文章:

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

对于那里的想法背后的一些原则,请参阅以下内容:

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

于 2010-11-17T18:47:47.370 回答
0

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.

于 2010-11-17T14:28:40.020 回答