Nyamiou The Galeanthrope
Nyamiou The Galeanthrope

Reputation: 1214

MongoDB locking accross collections workaround

On an existing project to workaround the fact that MongoDB doesn't have transactions and for concurrent modifications across multiple collections by an application on multiple servers there is a workaround using a distributed cache (Infinispan) that handle locks. I know that we should design the database in some way to avoid this problem but sometime there is no other way, so I wonder if some people have found other ways to deal with this problem without requiring q distributed cache.

Upvotes: 0

Views: 27

Answers (1)

Gerald Mücke
Gerald Mücke

Reputation: 11132

  1. If you need transactions don't use MongoDB, use a RDBMS instead.
  2. Put all information that need to be immediately persitent in one document.
  3. Make the application tolerant for eventual consistency

Assuming that option 1 and 2 are not applicable to your application now (because these are more up-front considerations), you should aim for option 3. For example by serving the content of each collection with a dedicated service and map the status of the "transaction" in the http codes (i.e. not-found, moved, modified etc) or just display incomplete information and push updates as soon as the transaction is complete etc.

Upvotes: 1

Related Questions