-
Type: Improvement
-
Resolution: Fixed
-
Priority: Major - P3
-
Affects Version/s: None
-
Component/s: Aggregation Framework
-
Fully Compatible
-
v4.4, v4.2
-
Query 2020-06-29
-
(copied to CRM)
Implementation inĀ SERVER-9507 only works when specific format for _id in $group is used:
// works db.newTest.explain(1).aggregate([ {$sort:{valueDate:1}}, {$group:{_id: "$valueDate", first: {$first: "$farmId"}}} ]).stages[0]["$cursor"]["executionStats"] { "executionSuccess" : true, "nReturned" : 2, "executionTimeMillis" : 0, "totalKeysExamined" : 2, "totalDocsExamined" : 2, ... } // doesn't work db.newTest.explain(1).aggregate([ {$sort:{valueDate:1}}, {$group:{_id: {v:"$valueDate"}, first: {$first: "$farmId"}}} ]).stages[0]["$cursor"]["executionStats"] { "executionSuccess" : true, "nReturned" : 5, "executionTimeMillis" : 0, "totalKeysExamined" : 10, "totalDocsExamined" : 5, ... }
- is related to
-
SERVER-53626 Minimize index scanning when retrieving distinct values grouped by more than one field
- Backlog
-
SERVER-9507 Optimize $sort+$group+$first pipeline to avoid full index scan
- Closed