[CSHARP-3067] $convert (aggregation) Created: 18/Apr/20 Updated: 28/Oct/23 Resolved: 16/Feb/22 |
|
| Status: | Closed |
| Project: | C# Driver |
| Component/s: | Linq |
| Affects Version/s: | None |
| Fix Version/s: | 2.14.0 |
| Type: | Bug | Priority: | Major - P3 |
| Reporter: | Christos Sakellarios | Assignee: | Unassigned |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||
| Epic Link: | CSHARP-3615 | ||||||||
| Description |
|
Is $convert aggregation supported at any way by the C# driver? I can't find a way to cast values other than using BsonDocument. Example:
User.MonthlyExpense_s is an integer but ac.Average returns decimal which results in strange numbers. So either during grouping or at least on a next step, I need to convert the _averageMonthlyExpenses to an integer. If I add a new Project stage to convert the averageMonthlyExpenses to Int, using any type of cast the driver throws an exception. Is there any way to make the cast?
|
| Comments |
| Comment by James Kovacs [ 16/Feb/22 ] | |||||||||||||||
|
This issue has been fixed in the new LINQ provider (known as LINQ3), which is included in the 2.14 release. Although this is a Fluent Aggregate expression, we use the configured LINQ provider to support Expressions in Fluent Aggregate. If you add a cast to your group expression similar to the following:
This will add a $project stage with a $convert after the $group stage similar to the following:
Configure your MongoClientSettings to use LinqProvider.V3 if you want to use this functionality. To configure a client to use the LINQ3 provider use code like the following
|