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

Max inside the lamda expression MQL translation is wrong

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 2.14.0
    • Affects Version/s: None
    • Component/s: None
    • Labels:
      None

      The max inside the lambda expression is not working as expected in the c# fluent aggregate syntax.

      C# driver version: 2.15.1

       db.remittance.insert({Payments: [{Date: ISODate("2020-06-01 04:22:59.948Z")}, \{Date: ISODate("2020-06-01 05:22:59.948Z")}, \{Date: ISODate("2020-06-01 06:22:59.948Z")}]})

      var query = coll.Aggregate() .Project(x => new ProjectResult

      { Payment = x.Payments == null ? null : x.Payments.First(y => y.Date == x.Payments.Max(y => y.Date)) }

      );

      Actual :

      db.remittance.aggregate([{ “$project” : { “Payment” : { “$cond” : { “if” :

      { “$eq” : ["$Payments", null] }

      , “then” : null, “else” : { “$arrayElemAt” : [{ “$filter” : { “input” : “$Payments”, “as” : “y”, “cond” : { “$eq” : ["$$y.Date",

      { “$max” : *“$$y.Payments.Date”* }

      ] } } }, 0] } } }, “_id” : 0 } }])

      Expected:

      db.remittance.aggregate([{ “$project” : { “Payment” : { “$cond” : { “if” :

      { “$eq” : ["$Payments", null] }

      , “then” : null, “else” : { “$arrayElemAt” : [{ “$filter” : { “input” : “$Payments”, “as” : “y”, “cond” : { “$eq” : ["$$y.Date",

      { “$max” : *“$$Payments.Date”* }

      ] } } }, 0] } } }, “_id” : 0 } }])

       

      I am trying to get the recent transaction by the date using the max function inside the lambda expression and I am not getting the expected result by this wrong translated query.

            Assignee:
            robert@mongodb.com Robert Stam
            Reporter:
            gsudhesh@gmail.com Sudhesh Gnanasekaran
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: