[CSHARP-1893] New DistinctMany method which is like Distinct but for array fields. Created: 13/Jan/17  Updated: 23/Jan/24  Resolved: 23/Jan/24

Status: Closed
Project: C# Driver
Component/s: API, Linq
Affects Version/s: 2.4.1
Fix Version/s: 2.24.0

Type: Improvement Priority: Major - P3
Reporter: Robert Stam Assignee: Robert Stam
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Documented
Related
is related to CSHARP-1891 Distinct should still work when TFiel... Closed
Documentation Changes: Needed
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?

New DistinctMany method may need to be documented.


 Description   

The Distinct method of IMongoCollection assumes that the member is a scalar value:

IAsyncCursor<TField> Distinct<TField>(FieldDefinition<TDocument, TField> field, FilterDefinition<TDocument> filter, DistinctOptions options = null, CancellationToken cancellationToken = default(CancellationToken))

Because of the way Distinct works with array members an additional overload is needed to correctly handle array members:

IAsyncCursor<TItem> DistinctMany<TItem>(FieldDefinition<TDocument, IEnumerable<TField>> field, FilterDefinition<TDocument> filter, DistinctOptions options = null, CancellationToken cancellationToken = default(CancellationToken))

Note that the return values are of type TItem, not TField.



 Comments   
Comment by Sergei Lipin [ 07/Dec/23 ]

I added a pull request to GitHub:
https://github.com/mongodb/mongo-csharp-driver/pull/1229

robert@mongodb.com I would really appreciate if you could take a look.

Comment by Robert Stam [ 13/Jan/17 ]

Due to the absence of this overload users who used Distinct with array members had to fudge the type of the field as illustrated by the repro of CSHARP-1891.

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