We have a case where we want to inspect the data of existing record before updating. While this is done, we do not want another thread to update the document. Basically, we need a way to synchronize the updates coming from different threads on a per document basis.
Instead of implementing something outside to lock the document for update, wondering if there is any inherent support
Give us an example? (e.g. what will be checked)
otherwise it’s difficult to give suggestions.
We have a collection that holds any type of data. We are API providers and we wrap the consumer data into our own wrapper and the API deals with only attributes of that wrapper. We want to give a feature to the consumers to provide a hook such that say they can decide to skip the update if in case a older version comes in and the document in the collection already has a newer version. Not everyone need that but some of our consumers may need that control over updates.
Basically its like acquiring a lock, process and release lock
Hello, @Vasu_Bathina! Welcome to the community!
You can assign to each update operation the modificationsRequested
timestamp and simply do not update documents that have modificationsRequested
with a higher value. This solution is described with example in this topic.
UpdateOne method returns update result on which it is clear if the doc is updated, or not. Then act accordingly.