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

Count Expression in Aggregation Definition silently does the wrong thing

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Major - P3 Major - P3
    • 2.8.0
    • 2.4.3
    • Linq
    • None
    • Minor Change

    Description

      Consider the following aggregation defintion

      DateTime now = DateTime.Now;
      Collection.Aggregate().Group(x => x.AdapterShortKey, group => new { CountFoo = group.Count(x => x.DepartureDate < now) });
      

      This code compiles and runs but does the wrong thing. Instead of counting the documents with the condition

      x.DepartureDate < now
      

      it counts all the documents.

      The workaround is to write

      group.Sum(x => x.DepartureDate < now ? 1 : 0)
      

      which does the correct thing.

      Attachments

        Activity

          People

            dmitry.lukyanov@mongodb.com Dmitry Lukyanov (Inactive)
            cypressious Kirill Rakhman
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: