Hi
I’m using MongoDB driver for .Net Core 3.1 and there is a wrong query translation when I’m using lambda expression in the Project stage of the Aggregation pipeline
The model contains the following definition:
public class BaseValidity
{
[BsonId]
[BsonRepresentation(BsonType.ObjectId)]
public string id { get; set; } = ObjectId.GenerateNewId().ToString();
}
And the query is:
var queryToExecute = _dataStreams.Aggregate()
.Match(...)
.Project(
dataStream => new {
validations = dataStream.episodes
.Select(
episode => episode.validations
.Where(validity => validity.id == baseValidityId).First()
).Where(validity => validity != null)
}
);
But the output of the project stage is:
{ "$project" : {
"validations" : {
"$filter" : {
"input" : {
"$map" : {
"input" : "$episodes",
"as" : "episode",
"in" : {
"$arrayElemAt" : [
{ "$filter" : {
"input" : "$$episode.validations",
"as" : "validity",
"cond" : **{ "$eq" : ["$$validity._id", "5f55fd057e29a07970048ce9"] }**
}}, 0
]}
}
},
"as" : "validity",
"cond" : {
"$ne" : [ "$$validity", null ]
}
}
}
}}
it should be:
{ "$eq" : ["$$validity._id", ObjectId("5f55fd057e29a07970048ce9")] }
Is there any workaround for this issue?