How to use change stream in java

I want to run a function whenever a new document is added to my collection. But for each is not applicable in the watch method. How to use change stream properly in java android.

Please help.

What is a RemoteMongoCollection? Is that a library you wrote or is it from a third party?

I am not too sure but I think you block needs to be between () not after.

You have { } but what you need is { } ). And your {} must implements Block< ChangeStreamDocument< Document > > and as such you must have a method public void apply( final ChangeStreamDocument change ).

I removed the changed it to MongoCollection and the forEach() was working, but I was not able to initialize the MongoCollection (ie. db).

Then I changed RemoteMongoClient to MongoClient, but then I was unable to initialize that also.
All the screenshots are below as I can’t upload more that one image in the forum.
Please help.

I am probably using “Remote” because I am using Stitch of MongoDB