[CSHARP-2194] Make IMongoCollection covariant Created: 15/Feb/18  Updated: 27/Oct/23  Resolved: 30/Jan/19

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

Type: Improvement Priority: Minor - P4
Reporter: Adrian Pinter Assignee: Vincent Kam (Inactive)
Resolution: Works as Designed Votes: 2
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Backwards Compatibility: Fully Compatible

 Description   

For my app, I'd like to define the following property on my data context class:

public IMongoCollection<BsonDocument> C => data.GetCollection<RawBsonDocument>( "c" );

My purpose is to have a single IMongoCollection instance from which I can retrieve raw documents, but into which I can also insert non-raw ones.

This improvement involves adding `out` to IMongoCollection's definition:

public interface IMongoCollection<out TDocument>



 Comments   
Comment by Vincent Kam (Inactive) [ 30/Jan/19 ]

Hello HappyNomad,
Thank you for your feedback. If you wish to retrieve raw documents and insert-non-raw documents, I would recommend using two IMongoCollection objects, one for reading raw documents and one for inserting non-raw documents. IMongoCollection objects are fairly lightweight and shouldn't consume a lot of memory.
Kind regards,
Vincent

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