Since this feature is relatively new (mongo 3.6) I found very few java examples. My questions: 1. What is the best practices for watching change streams? 2. Does it have to be a blocking call to watch the stream? (This means a thread per collection which is less desired) This is the example I encountered:
http://mongodb.github.io/mongo-java-driver/3.6/driver/tutorials/change-streams/
The blocking call is: collection.watch().forEach(printBlock);
Thanks, Rotem.
Change streams make a lot more sense when you look at them in the context of reactive streams. It took me a while to realize this concept has a much broader existence than just the MongoDB driver.
I recommend reviewing the article above and then looking at the example provided here. The two links helped clear things up, and provided insight on how to write code leveraging the reactive streams Mongo driver, which is non-blocking.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With