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

$convert (aggregation)

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open
    • Priority: Major - P3
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: Linq
    • Labels:
      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

            Activity

              People

              Assignee:
              dmitry.lukyanov Dmitry Lukyanov
              Reporter:
              chsakell@gmail.com Christos Sakellarios
              Participants:
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Dates

                Created:
                Updated: