C100DEV Aggregation Framework Practice Question
Which stage should be placed first in an aggregation pipeline to optimize performance when filtering a large collection based on an indexed field?
⚠ Common exam trap
Candidates often place $project or $group stages before $match, which forces MongoDB to process the entire collection, rendering the index useless and significantly increasing memory consumption and execution time.
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
$match
The $match stage filters documents before they pass to subsequent stages, significantly reducing the data volume processed by memory-intensive operations like $sort or $group. Placing it first allows MongoDB to utilize indexes, which minimizes disk I/O and RAM usage. Efficient pipeline construction is critical for scalability in production environments, as reducing the input set early directly impacts the latency and resource consumption of the entire aggregation operation.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
$project
Why it's wrong here
Projecting fields at the start does not filter documents, meaning the entire collection remains in the pipeline. This increases memory overhead for subsequent stages and prevents the use of indexes for filtering logic. Using $project initially fails to leverage the query optimizer's ability to prune the input set early.
- ✓
$match
Why this is correct
The $match stage serves as a query filter that can utilize existing indexes when placed at the beginning of a pipeline. By reducing the number of documents passed to downstream stages, it saves CPU and memory. This is the standard practice for performance optimization in MongoDB aggregation pipelines.
- ✗
$group
Why it's wrong here
Grouping at the start forces the aggregation engine to process every document in the collection before any filtering occurs. This is highly inefficient, as $group is a blocking stage that requires substantial memory to maintain state. It cannot leverage indexes for filtering, leading to poor performance on large datasets.
- ✗
$sort
Why it's wrong here
Sorting the entire collection before filtering is computationally expensive and memory-intensive, often forcing an in-memory sort if the dataset exceeds the 100MB limit. Sorting should only occur after the dataset has been reduced by a $match stage to ensure the operation remains performant and avoids unnecessary overhead.
About these practice questions
Courseiva writes every C100DEV question from scratch — 259 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or dumps. Learn why practice questions differ from exam dumps →
JA
Written and reviewed by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
Last reviewed September 2026 · checked against the official MongoDB exam blueprint
This C100DEV practice question is part of Courseiva's free MongoDB certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the C100DEV exam.