This should be done inside $unpackBucket's doOptimizeAt(). This only needs to handle the $project immediately after $unpackBucket.
- is depended on by
SERVER-53467 Investigate performance of $_internalUnpackBucket over BSON
SERVER-53977 Allow rewrite to produce only empty documents in $unpackBucket if it is followed by $count