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

$convert (aggregation)

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Major - P3 Major - P3
    • 2.14.0
    • None
    • Linq
    • 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

        Activity

          People

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

            Dates

              Created:
              Updated:
              Resolved: