Details
-
Bug
-
Resolution: Fixed
-
Major - P3
-
None
-
None
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:
var excercice1Aggregate = collection.Aggregate() |
.Match(Builders<User>.Filter.Gte(u => u.Salary, 1500) &
|
Builders<User>.Filter.Lte(u => u.Salary, 3000))
|
.Group(u => u.Gender,
|
ac => new |
{
|
gender = ac.Key,
|
averageMonthlyExpenses = ac.Average(u => u.MonthlyExpenses), // needs to convert |
total = ac.Sum(u => 1)
|
})
|
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?
Attachments
Issue Links
- duplicates
-
CSHARP-2924 Consider adding conversion logic into a generated Project query for Aggregate when it's necessary
-
- Closed
-