4 ms·
I've been developing using MongoDB for a few months now and the thing that always comes back to me as missing is the need to group a set of actions so that they
by matan_a 15y ago
I've been developing using MongoDB for a few months now and the thing that always comes back to me as missing is the need to group a set of actions so that they perform atomically. It's not exactly meaning i need transactions (i don't care about the commit/rollback part), just need the need to say - hey server, do X, Y, and Z as a batch so that another thread won't do something in the middle of that.
The general consensus on this is to structure your data so that it encapsulates your business needs in one document structure (which is atomic on changes), but i find it hard to always conform to in the real world.
So now i have to use zookeeper (memcached also works) to setup global locks on those specific batch update actions. I guess it's a small price to pay right? Right?
- veesahni 15y agoI believe MongoDB's server side functions allow you to create an atomic grouping of operations.. i.e. store a function and call it by db.eval() See the following: http://www.mongodb.org/display/DOCS/Server-side+Code+Execution#Server-sideCodeExecution-Storingfunctionsserverside http://www.mongodb.org/display/DOCS/Server-side+Code+Executi... http://www.mongodb.org/display/DOCS/Server-side+Code+Execution#Server-sideCodeExecution-NotesonConcurrency http://www.mongodb.org/display/DOCS/Server-side+Code+Executi...
- matan_a 15y agoThanks for the suggestion, but still not ideal. It performs a global lock on the DB which would block all operations while it computes.
- stonemetal 15y agoI tend to use a lock just long enough to write a transaction document. After you get the transaction captured in a document you can go back and fix up the primary documents without a lock.