I’m using KMongo, and I’m looking for a way to automatically update documents inside mongo db, every time a document is touched/retrieved/updated/… I was wondering if there is some built in functionallity or some specific way to do this. Thank you in advance!
Kmongo is a 3rd party project for kotlin. The java driver support change streams which is probably what you are looking for.
I am not familiar with kmongo but if its based on the mongo java driver it might have this capability…
If you can use Atlas as your deployment you can use build in trigger mechanism which is client agnostic:
Hope this helps.
Thank you for your response, it was really useful
Kotlin is based on java and there is a function called watch(), that can listen to any changes that go to a db/colleection/deployment, same as shown in the java driver documentation from above.
There is a thing that i couldn’t figure out, so while using a change stream, does it act as a middleware? and can I actually interfere with the mongo operation? or is this change stream acting only as a listener that returns all activity that already happened ( for example if I insert a document, will the change stream show me this activity after it was inserted in db or before it was actually inserted? )
Hope this makes sense
The change stream listen to the oplog collection and. Filter the needed events after they happened. It cannot block ot interfere with any of the applied operations.
This is why the oplog size and resume data are so coupled as the changestream seek for ita information there.
Thank you very much @Pavel_Duchovny! I have a much clearer understanding on how the change stream works now