-
Type: Bug
-
Resolution: Fixed
-
Priority: Major - P3
-
Affects Version/s: None
-
Component/s: Linq
-
None
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:
Unable to find source-code formatter for language: csharp. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
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?
- duplicates
-
CSHARP-2924 Consider adding conversion logic into a generated Project query for Aggregate when it's necessary
- Closed