> db.a.insert({_id: 1}); > db.a.explain().aggregate([{$group: {_id: "$$REMOVE", o: {$first: "$a"}}}]).queryPlanner.winningPlan.slotBasedPlan.stages; [2] mkbson s9 [_id = s6, o = s8] true false [2] group [s6] [s8 = first (fillEmpty (s7, null))] [2] project [s7 = getField (s4, "a")] [2] project [s6 = Nothing] [1] scan s4 s5 none none none none [] @"39336b7b-b5b8-4328-8ae6-e5a7e9ce31ae" true false
project [s6 = Nothing] should be project [s6 = fillEmpty (Nothing, null)]. We can't do project [s6 = null] because EConstant does not have a method to examine its value.
This is a bug in $group SBE stage builder and so backport to v6.0 is necessary.