Using an Index with Mongo's $first Group Operator
问题 Per Mongo's latest $group documentation, there is a special optimization for $first: Optimization to Return the First Document of Each Group If a pipeline sorts and groups by the same field and the $group stage only uses the $first accumulator operator, consider adding an index on the grouped field which matches the sort order. In some cases, the $group stage can use the index to quickly find the first document of each group. It makes sense, since only the first entry in an ordered index