0

Provided that I have Worker and Admin updating the collection at the same time. How do I ensure that Admin always win?

Admin request this Record.update({testField: "test}, {amount : 200},...)

Worker request this Record.update({testField: "test}, {amount : 999},...)

How to ensure that the final amount will always be 200 if they press Update at the same time?

Zanko
  • 4,298
  • 4
  • 31
  • 54
  • The premise here doesn't really make sense. They can't happen at exactly the same time; whichever one occurs last will win. – JohnnyHK Dec 24 '15 at 03:28
  • Sorry for the confusion. What I meant to say was press update roughly at the same time so the update of admin might come before worker. (In this case worker will win). But is there any way for me to always let admin win? Any special mongodb operator? I want to design a database that allow admin to approve the record. But while unapproved, worker can still edit the record. So there will be a chance that admin approved but worker edit it. – Zanko Dec 24 '15 at 04:20
  • Ah, you likely want to use optimistic concurrency on the worker update, where it will qualify its update to check that the record isn't yet approved. How can you tell if a doc is approved? – JohnnyHK Dec 24 '15 at 04:43
  • 1
    Thank you for your response. This is a simplified version of concurrent updates. The real question was posted but wasn't recieving enough answer. I hope you can provide some insight to this. http://stackoverflow.com/questions/34443133/mongodb-integrity-update-edge-case Do you possibly have a link for me to read on? There isn't seem to be much material on these edge cases. I have read "Update if current" and is still trying to wrap my head around it. – Zanko Dec 24 '15 at 04:48
  • See my answer there. Next time, just edit your existing question to add more details instead of creating a duplicate question. – JohnnyHK Dec 24 '15 at 05:23

0 Answers0