Aggregation $group with 10 000 000 documents

A good solution could be using the Computed Pattern

Building with Patterns: The Computed Pattern | MongoDB