burger
burger

Reputation: 5883

What is the proper way to keep track of updates in progress using MondoDB?

I have a collection with a bunch of documents representing various items. Once in a while, I need to update item properties, but the update takes some time. When properties are updated, the item gets a new timestamp for when it was modified. If I run updates one at a time, then there is no problem. However, if I want to run multiple update processes simultaneously, it's possible that one process starts updating the item, but the next process still sees the item as needing an update and starts updating it as well.

One solution is to mark the item as soon as it is retrieved for update (findAndModify), but it seems wasteful to add a whole extra field to every document just to keep track of items currently being updated.

This should be a very common issue. Maybe there are some built-in functions that exist to address it? If not, is there a standard established method to deal with it?

I apologize if this has been addressed before, but I am having a hard time finding this information. I may just be using the wrong terms.

Upvotes: 0

Views: 213

Answers (1)

kris
kris

Reputation: 23592

You could use db.currentOp() to check if an update is already in flight.

Upvotes: 1

Related Questions