kmongo
kmongo copied to clipboard
Support optimistic concurrency
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.
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