Reputation: 31
I am new to mongodb and using a mongodb database collection for my simple queueing system. I want to be able to run multiple instances of my consumer. I am using the findOneAndUpdate()
operation to pick up a job a pending job and mark it processing before processing it. If I have multiple instances of the consumer running is there any case that consumers running concurrently would pick the same job. I am using the native mongodb js driver
My consumer code looks as follows
const job = await db.collections('jobs').findOneAndUpdate({ status: 'pending'},
{ $set: { status: "processing" } }
);
Upvotes: 2
Views: 277