Skip to main content
Journey Uncommon Logo
JourneyUncommon
mediumMongoDBaggregation $match $groupSingle-choice MCQ

In the aggregation pipeline below, `status` and `region` are both indexed. Why is placing `$match` before `$group` important here beyond just correctness?

db.sales.aggregate([ { $match: { status: "completed" } }, { $group: { _id: "$region", total: { $sum: "$amount" } } } ]);