Thursday, 25 May 2017

Mongodb atomic queries

I have a mongodb database where multiple node processes read and write documents. I would like to know how can i make that so only one process can work on a document at a time. (Some sort of locking) that is freed after the process finished updating that entry.

My application should do the following:

  • Walk through each entry one by one with a cursor.
  • (Lock the entry so no other processes can work with it)

  • Fetch information from a thirdparty site.

  • Calculate new information and update the entry.
  • (Unlock the document)

Also after unlocking the document there will be no need for other processes to update it for a few hours.

Later on i would like to set up multiple mongodb clusters so that i can reduce the load on the databases. So the solution should apply to both single and multiple database servers. Or at least using multiple mongo servers.



via Azarus

No comments:

Post a Comment