-
Type:
Bug
-
Resolution: Fixed
-
Priority:
Critical - P2
-
Affects Version/s: 2.6.0
-
Component/s: LINQ
-
None
-
Environment:Windows 10, Visual Studio 2017
-
None
-
None
-
None
-
None
-
None
-
None
-
None
I noticed this issue while doing the course on university.mongodb.com
On Homework 3.1 we are requested to remove the smallest score from a list.
I did this query in .net to get all the scores that are greater than the minimum:
studentCollection.AsQueryable().Select(student => new { student.Id, Scores = student.Scores.Where(sc1 => sc1.Score > student.Scores.Min(sc2 => sc2.Score)) }).ToList();
The generated command is:
{ "aggregate" : "students", "pipeline" : } } }, "_id" : 0 } }" target="_blank" rel="noopener">{ "$project" : { "Id" : "$_id", "Scores" : { "$filter" : { "input" : "$scores", "as" : "sc1", "cond" : {{color:#d04437} "$gt" : ["$$sc1.score", { "$min" : "$$sc1.scores.score" }] } } }, "_id" : 0 } }, "cursor" : { }, "lsid" : { "id" : CSUUID("8cea95ec-7e89-4752-a3d4-9d7ea628cef9") } }
If you look closely you will notice that the $min condition is wrong, it's using "$$sc1.scores.score" instead of "$scores.score" ($$sc1 = $scores).
Also I've tried to do linked Select, but it's not supported:
studentCollection.AsQueryable().Select(student => new { student.Id, MinScore = student.Scores.Min(sc1 => sc1.Score), Scores = student.Scores })
.Select(student => new { student.Id, Scores = student.Scores.Where(sc2 => sc2.Score > student.MinScore) }).ToList();
The Students collection:
{
"_id" : 137,
"name" : "Tamika Schildgen",
"scores" : [
Unknown macro: { "type" },
Unknown macro: { "type" },
Unknown macro: { "type" }]
}