kmongo icon indicating copy to clipboard operation
kmongo copied to clipboard

Support optimistic concurrency

Open Legion2 opened this issue 3 years ago • 1 comments

Mongoose supports optimistic concurrency, which means documents can concurrently be accessed and modified, but are checked for conflicts on write operations. This is required to prevent lost updates when multiple clients write to mongodb at the same time. Mongoose uses a version key to store and validate the document was not updated between read and write operations by other clients.

This could be implemented by the user of kmongo, however it is a cross-cutting feature and would require to be applied to the schema and all mongodb commands.

Legion2 avatar Apr 26 '21 09:04 Legion2

I made a small example how to add optimistic locking with extension-functions. Feel free to make a lib out of it or copy it into kmongo https://github.com/nielsfalk/kmongo-optimisic-locking/blob/main/src/main/kotlin/de/nielsfalk/kmongo/optimisiclocking/OptimisticLocking.kt

nielsfalk avatar Feb 15 '23 16:02 nielsfalk