Search code examples
mongodbclojurewatchmongodb-javachangestream

MongoDB `watch` for `insert`s is not working


I have watched a collection using the following as filter for the watch function of com.mongodb.client.internal.MongoDatabaseImpl object:

(java.util.Arrays/asList
  (into-array
    [(com.mongodb.client.model.Aggregates/match
       (com.mongodb.client.model.Filters/and
         (java.util.Arrays/asList
           (into-array Object
                       [(com.mongodb.client.model.Filters/in "operationType"
                          (java.util.Arrays/asList
                            (into-array ["insert" "update" "delete" "replace"])))]))))]))

As you can see, I have watched the collection on all the operation types, but the watcher is only picking up changes for the update operations and nothing else.

Can anyone point me in the right direction?

Also, doing inserts is causing the watcher thread to hang and it's also preventing further watches on the collection, at which point I have to reset my REPL state to make the update watches work.

FYI, the org.mongodb/mongo-java-driver version that I am using is "3.12.7"


Solution

  • Turns out this was a different issue. I was calling the .getRemovedFields method on the updateDescription event when I can watching for inserts, which threw an error inside my async code.