I've started dealing with MongoDB change streams and have set up some streams to watch for changes on around 30 databases. I need to watch only two collections and I was wondering if I can write some pipe or filter to watch collections with the name or part of the name provided. For example I get the collection name from the namespaceDocument of ChangeStreamDocument, and I wanna watch collections that are equal to "players" for example, on all of the databases.I'm watching the whole server for changes, but now i get notification for every collection that is changed and I don't want that, only specific collections.
final ChangeStreamPublisher<Document> publisher = client.watch(Arrays.asList(
Aggregates.match(
Filters.in("operationType", Arrays.asList("insert", "update", "delete"))
))).fullDocument(FullDocument.UPDATE_LOOKUP);
I was thinking if I could put some filter there to make the stream watch only collections with corresponding names.
Documentatin: https://docs.mongodb.com/manual/changeStreams/