MongoDB Optimistic Locking Retry
Clash Royale CLAN TAG #URR8PPP MongoDB Optimistic Locking Retry Suppose I have multiple clients and all are hooked to the same Mongo Database. Each document has a version number to ensure that data isn't lost. Document #1 { __v: 0, _id: 1, quantity: 5 } An update hits the server to update the document to quantity 10, using __v as 0. Collection.update({_id: 1, __v: 0}, {$set: {quantity: 10}, $inc: {__v: 1}}); Now just say that another updates comes in right after as the following: Collection.update({_id: 1, __v: 0}, {$set: {quantity: 15}, $inc: {__v: 1}}); Since the __v of the update is not 1, this update does not happen, so the client receives an error. This is what I am attempting to resolve. Issue #1 Merging the 2nd update with the old __v: 0 document could work if the properties don't conflict, but if they do like in this example, not sure how to solve this issue. I am thinking maybe I could keep the history of the documents, somehow compare the update with ...