Watch does not work for inserts, only updates

I am watching a collection and my watch function runs fine, but fails and hangs for inserts. The value of my filter is as the following:

[#object[com.mongodb.client.model.Aggregates$SimplePipelineStage 0x6ed03635 "Stage{name='$match', value=And Filter{filters=[Operator Filter{fieldName='operationType', operator='$in', value=[insert, update, delete, replace]}]}}"]]

As you can see, I have added a bunch of operation types, but my watch function only picks up updates, and nothing else.

Can someone point me in the right direction?

I am creating filter for my watch function in the following manner. Pardon me, the code is in the Clojure programming language:

(def watch-filter
  (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
                 (into [(com.mongodb.client.model.Filters/in "operationType"
                          (java.util.Arrays/asList
                            (into-array ["insert", "update", "delete", "replace"])))])))))])))

NOTE: def is just a macro for creating variables and into-array is a function for creating java arrays
Which I am using in my db cursor iterator like this:

(-> ^com.mongodb.client.internal.MongoDatabaseImpl db
    (#(.getCollection ^com.mongodb.client.internal.MongoDatabaseImpl %
                      ^String "mongo-coll-name"))
    (#(.watch ^com.mongodb.client.internal.MongoCollectionImpl %
              ^java.util.List watch-filter))
    (#(.fullDocument ^com.mongodb.client.ChangeStreamIterable %
                     com.mongodb.client.model.changestream.FullDocument/UPDATE_LOOKUP))
    (#(.iterator ^com.mongodb.client.internal.Java8ChangeStreamIterableImpl %)))

NOTE: The -> is a macro which translates into java’s db.getCollection("mongo-coll-name").watch... in the above case.
FYI, the org.mongodb/mongo-java-driver version that I am using is "3.12.7"

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.

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.