Uploaded image for project: 'C# Driver'
  1. C# Driver
  2. CSHARP-3067

$convert (aggregation)

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 2.14.0
    • 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?

       

       

            Assignee:
            Unassigned Unassigned
            Reporter:
            chsakell@gmail.com Christos Sakellarios
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: