Cannot resolve watch() method in java

I want to use the change stream to run a function whenever a new document is created in the database.
But the compiler cannot resolve the watch() method.

Hi @Rahul_Sonia,

Welcome to the MongoDB Community forums!

Can you provide the version of the MongoDB Java driver you’re using? The latest version is 4.0.1 and (according to the documentation) should have a watch method. Also, is it failing to compile or is it only failing to properly auto-complete in the IDE?



Thanks,I actually had the outdated version.