I am trying to implement a structure that keeps itself up-to-date by using find and watch combination. E.g. for users collection we find all users and store them in a hashmap. After that we open watch stream and update our hashmap according to incoming events. But there is problem - if change occurs between reading users and opening a stream we might end up desynchronized.
My idea was to use startAtOperationTime option but we can't reliably know the timestamp we need. Also I don't see a way to do it with transactions.
The question is - how do we open change stream exactly after read operation and don't lose any data.
question from:
https://stackoverflow.com/questions/65545440/mongodb-find-and-watch 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…