[CSHARP-2326] Distinct by multiple Keys Created: 12/Jul/18 Updated: 14/Jun/19 Resolved: 06/Feb/19 |
|
| Status: | Closed |
| Project: | C# Driver |
| Component/s: | Read Operations |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Task | Priority: | Major - P3 |
| Reporter: | Prashant | Assignee: | Wan Bachtiar |
| Resolution: | Done | Votes: | 0 |
| Labels: | question | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Description |
|
Find distinct records with the help of multiple keys within a collection in C#. Here, multiple keys are present in an string array. For example: If we have a collection, collection = { [ {firstName: "John", lastName: "Cena", age: 40},{firstName: "Prashant", lastName: "Gupta", age: 45}] } and we have an array: multiplekeys = {"lastName","age"} How can we find the distinct records in the collection using multiple keys? |
| Comments |
| Comment by Wan Bachtiar [ 18/Jan/19 ] | ||||||||
|
Hi Prashant, You can use MongoDB Aggregation Pipeline to group by multiple fields to find distinct records as below example:
See also $group pipeline stage for more information. Please note that CSHARP project is for reporting bugs or feature suggestions for the MongoDB C# driver. For MongoDB .NET/C# usage discussion please post on the mongodb-user group. Regards, |