Using C# driver 2.20.0 and subscribing for changed documents with MongoClient.WatchAsync() (i.e. subscribing for Inserted documents for the whole deployment, all databases, all collections.
This works just fine, but I read in the documentation that a ChangeStreamOperationType.Invalidate will be the consequence of e.g. a renamed or dropped collection if the stream is setup on the collection, ditto if database, but nothing is stated if the stream is setup on MongoClient.
Is ChangeStreamOperationType.Invalidate at all possible for a stream setup on a MongoClient?
If yes, what can I do with the deployment to test for it?
We can get a cursor by using one of the IMongoCollection. Watch() methods, one of the IMongoDatabase. Watch() methods or IMongoClient. Watch() methods.
These have different “scopes”, IMongoCollection. Watch() reurns a cursor to get change document from that specific collection only while IMongoClient.Watch returns a cursor to get change documents from all collections in all databases (the whole “deployment”)
Change streams opened on collections raise an invalidate event when a drop, rename, or dropDatabase operation occurs that affects the watched collection.
Change streams opened on databases raise an invalidate event when a dropDatabase event occurs that affects the watched database.
in official manual, it doesn’t say if a “mongodb client” stream can raise invalidate event or not. So only the implementer can give an answer here.