Covering index for $group/$sum in MongoDB aggregation (with hint)
MongoDB indexes enable quick equality and range filtering (with $match) and ordering (with $sort). For aggregation operations like $group with $first or $last accumulators, indexes can dramatically improve performance through the DISTINCT_SCAN optimization. However, for hash-based aggregations such as $group with $sum or $sortByCount, there’s not such optimization. While indexes can provide significant performance benefits…