How to filter change stream using fullDocument.<field> in Java

Disclaimer:

  • Sorry for my bad English.
  • I am new to MongoDB.

Hi There,

I am trying to filter a change stream using Java. I am only interested in changes where the fullDocument.requesterId matches my criteria.

Unfortunately it does not work. I still get all changes.

This is how the ChangeStreamDocument looks like:

ChangeStreamDocument{ operationType=OperationType{value='insert'}, namespace=Machine2Machine.Messages, destinationNamespace=null, fullDocument=Document{{_id=ad69f54f-3d4d-49ce-a70d-951efb58750e, type=RESPONSE, requesterId=33b19ba9-b7c0-4c4e-822d-162b7894bec8, status=PENDING, value=Hello}}, documentKey={"_id": "ad69f54f-3d4d-49ce-a70d-951efb58750e"}, clusterTime=.........}

This is what I do:

mongoCollection.watch(asList(Aggregates.match( Filters.eq("fullDocument.requesterId", requesterId)) )).fullDocument(FullDocument.UPDATE_LOOKUP).subscribe(this);

I got it from several sources. One of them is https://blog.codecentric.de/en/2018/01/change-streams-mongodb-3-6/

What do I miss?

Any help is really appreciated.

Thanks

Sorry my bad.
The above works.
Turns out that the publisher I use in combination with the reactive stream driver was the actual problem.

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