MongoDB Enterprise > db.group_conversion_to_distinct_scan.explain().aggregate([{ $sort: { str: 1, d: 1 } }, { $group: { _id: "$str", accum: { $first: "$d" } } }]); { "explainVersion" : "2", "queryPlanner" : { "namespace" : "test.group_conversion_to_distinct_scan", "indexFilterSet" : false, "parsedQuery" : { }, "queryHash" : "FB9A89A9", "planCacheKey" : "0C288E96", "optimizedPipeline" : true, "maxIndexedOrSolutionsReached" : false, "maxIndexedAndSolutionsReached" : false, "maxScansToExplodeReached" : false, "winningPlan" : { "queryPlan" : { "stage" : "GROUP", "planNodeId" : 4, "inputStage" : { "stage" : "SORT", "planNodeId" : 3, "sortPattern" : { "str" : 1, "d" : 1 }, "memLimit" : 104857600, "type" : "simple", "inputStage" : { "stage" : "PROJECTION_SIMPLE", "planNodeId" : 2, "transformBy" : { "d" : true, "str" : true, "_id" : false }, "inputStage" : { "stage" : "COLLSCAN", "planNodeId" : 1, "filter" : { }, "direction" : "forward" } } } }, "slotBasedPlan" : { "slots" : "$$RESULT=s15 env: { s3 = 1685019940032 (NOW), s2 = Nothing (SEARCH_META), s1 = TimeZoneDatabase(Asia/Makassar...Pacific/Noumea) (timeZoneDB) }", "stages" : "[4] mkbson s15 [_id = s12, accum = s13] true false \n[4] group [s12] [s13 = first((s4 ?: null))] spillSlots[s14] mergingExprs[first((s14 ?: null))] \n[4] project [s12 = (s5 ?: null)] \n[3] sort [s10, s11] [asc, asc] [s4, s5] \n[3] project [s10 = \n if (isArray(s5) ?: false) \n then (_internalLeast(s5) ?: undefined) \n else (s5 ?: null) \n, s11 = \n if (isArray(s4) ?: false) \n then (_internalLeast(s4) ?: undefined) \n else (s4 ?: null) \n] \n[3] project [s9 = (!((isArray(s5) ?: false)) || (!((isArray(s4) ?: false)) || fail(2, \"cannot sort with keys that are parallel arrays\")))] \n[2] mkbson s8 s6 [d, str] keep [] true false \n[1] scan s6 s7 none none none none none none lowPriority [s4 = d, s5 = str] @\"47ba07a1-1d34-490b-886f-42ec54c3e327\" true false " } }, "rejectedPlans" : [ ] }, "command" : { "aggregate" : "group_conversion_to_distinct_scan", "pipeline" : [ { "$sort" : { "str" : 1, "d" : 1 } }, { "$group" : { "_id" : "$str", "accum" : { "$first" : "$d" } } } ], "explain" : true, "cursor" : { }, "lsid" : { "id" : UUID("34460f2a-08bd-4247-a5d1-5a4210607ef9") }, "$db" : "test" }, "serverInfo" : { "host" : "ip-10-0-1-70", "port" : 20000, "version" : "7.1.0-alpha-1019-gd5dff6d", "gitVersion" : "d5dff6d99d6b569864e7dd71a8bea88f9017aa3c" }, "serverParameters" : { "internalQueryFacetBufferSizeBytes" : 104857600, "internalQueryFacetMaxOutputDocSizeBytes" : 104857600, "internalLookupStageIntermediateDocumentMaxSizeBytes" : 104857600, "internalDocumentSourceGroupMaxMemoryBytes" : 104857600, "internalQueryMaxBlockingSortMemoryUsageBytes" : 104857600, "internalQueryProhibitBlockingMergeOnMongoS" : 0, "internalQueryMaxAddToSetBytes" : 104857600, "internalDocumentSourceSetWindowFieldsMaxMemoryBytes" : 104857600, "internalQueryFrameworkControl" : "trySbeEngine" }, "ok" : 1 }