Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Question about mongodb capped collections + tailable cursors

I'm building a queueing system that passes a message from one process to another via a stack implemented in mongodb with capped_collections and tailable cursors.

The receiving processes loops infinitely looking for new documents in the capped_collection, and when it finds one it performs an operation.

My question is, if I implement multiple receiving processes is there a way to guarantee that a new document will only be read once by one of the processes using a tailable cursor? The goal is to avoid the operation being performed twice if there are two receiving processes looking for new messages in the queue. I'm relatively new to mongodb programming so I'm still getting a feel for all of its features.

like image 690
Casey Flynn Avatar asked Nov 05 '22 13:11

Casey Flynn


1 Answers

MongoDB documents contain a thorough description of ways to achieve an atomic update. You cannot ensure that only one process receives the new document but you can implement an atomic update after receiving it to ensure that only one process acts on it.

like image 101
Ian Mercer Avatar answered Nov 09 '22 16:11

Ian Mercer