|
Currently, $count aggregation stage will produce a project stage for the group id, even when the group id is constant.
For aggregation:
db.coll.explain().aggregate([{$count: "n"}]).stages[0].$cursor.queryPlanner.winningPlan.slotBasedPlan.stages
|
It produces:
[2] mkobj s9 [_id = s6, n = s7] true false
|
[2] group [s6] [s7 = sum(1)] spillSlots[s8] mergingExprs[sum(s8)]
|
[2] project [s6 = (null ?: null)]
|
[1] scan s4 s5 none none none none [] @"e8cac054-9809-447e-94d0-1225895e2c70" true false
|
The project stage is evaluated for every document and is not necessary.
|