-
Type: Bug
-
Resolution: Fixed
-
Priority: Major - P3
-
Affects Version/s: None
-
Component/s: None
-
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.