문제

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.

도움이 되었습니까?

해결책

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.

다른 팁

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top