[CSHARP-4645] WatchAsync() signatures are not consistent Created: 08/May/23  Updated: 08/May/23  Resolved: 08/May/23

Status: Closed
Project: C# Driver
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Improvement Priority: Unknown
Reporter: Magne Ryholt Assignee: Boris Dogadov
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to CSHARP-4646 Support namespace queries in ChangeSt... Closed
Documentation Changes Summary:

1. What would you like to communicate to the user about this feature?
2. Would you like the user to see examples of the syntax and/or executable code and its output?
3. Which versions of the driver/connector does this apply to?


 Description   

The signature for a MongoCollection.WatchAsync allows a pipeline argument as PipelineDefinition<ChangeStreamDocument<TDocument>, TResult>

The signatures for MongoDatabase and MongoClient allows only PipelineDefinition<ChangeStreamDocument<BsonDocument>, TResult>

Any particular reason why only Collection accepts a strongly typed pipeline?



 Comments   
Comment by Boris Dogadov [ 08/May/23 ]

Thanks for reporting this. Closing this ticket, and will track this issue in CSHARP-4646.

Comment by Magne Ryholt [ 08/May/23 ]

Thanks a lot, really helpful.
Can I close the issue myself?

Comment by Boris Dogadov [ 08/May/23 ]

Thanks for the additional information.

Yes, the driver does not support rendering namespace queries, we'll be tracking this feature in CSHARP-4646.

And you are correct, the workaround for now would be specifying the pipeline via json.

Comment by Magne Ryholt [ 08/May/23 ]

Thanks

I kind of understand and kind of not

the streamed document is of the type defined by the pipeline, which is T for a Collection and just has to be BsonDocument for Database and Client.

The BsonDocument from a e.g. Client stream may be deserialized to T anyway.

I can solve my "problem" by specifying the pipeline match stage with raw Bson operations, but strongly typing is always safer and more readable.

The reason why I ask is for keeping number of connections down because I want to be informed of many of the databases (hundreds), but not all and the pipeline cannot match on e.g. <changeDocument>.DatabaseNamespace.DatabaseName == <some name> because it throws when WatchAsync is called stating that there is no serializer registered for DatabaseNamespace, which, as described above, may be solved by raw Bson (please correct me if I am wrong)

I could subscribe for changes from all databases and do the filtering client-side after deserializing to T, but I assume that creates much more network use (and possibly higher load server-side)

Comment by Boris Dogadov [ 08/May/23 ]

Hi magne@ryholt.no, thanks for the question.

MongoDatabase.Watch watches all collections across the database and MongoClient.Watch watches all collections across all databases.
Each collection could have a different type, therefore BsonDocument is the most basic type that can be used for such operation.

Comment by Service Account: DBX TPM [ 08/May/23 ]

Hi magne@ryholt.no, thank you for reporting this issue! The team will look into it and get back to you soon.

Generated at Wed Feb 07 21:48:52 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.