C100DBA Indexing and Performance Practice Question
An operations engineer notices that a frequently executed aggregation pipeline fails with a 'Exceeded memory limit for $sort' error. Which index configuration best resolves this memory constraint?
⚠ Common exam trap
Candidates often create an index only on the sort field, forgetting that the query filter must also be satisfied by the index to avoid an in-memory sort operation.
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
✓
Create a compound index matching the query's match filter fields followed by the sort fields in exact order.
MongoDB restricts in-memory operations like sorting to a fixed buffer size. When a query cannot satisfy its sort requirements from an index, it loads documents into memory. Providing a compound index containing the query's equality, range, and sort fields allows the execution engine to stream sorted results directly.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
Create a wildcard index across all collection fields to capture unpredictable aggregation pipeline projections.
Why it's wrong here
Wildcard indexes are designed for flexible, highly unstructured schemas with unpredictable query paths. They do not maintain the strict compound ordering necessary to satisfy complex multi-field sorting requirements, failing to prevent memory allocation exceptions during aggregation execution.
- ✓
Create a compound index matching the query's match filter fields followed by the sort fields in exact order.
Why this is correct
Matching the equality and sort fields within a single compound index enables the storage engine to deliver documents in the precise sorted order required by the pipeline. This eliminates the need for an in-memory sort stage, safely avoiding the strict RAM threshold limits.
- ✗
Increase the global cluster parameter maxInMemorySortBytes beyond the default allocation limit.
Why it's wrong here
Raising global memory limits masks inefficient query patterns and risks out-of-memory crashes on the underlying operating system. Optimizing the indexing strategy is the standard operational practice to resolve sort memory errors permanently without compromising node stability.
- ✗
Enable allowDiskUse on every query connection string globally across the application configuration.
Why it's wrong here
Offloading sorts to temporary disk files incurs heavy input-output latency penalties and degrades overall cluster performance. Indexes should always be designed to resolve sorting requirements in memory or directly from disk-based B-tree traversal whenever feasible.
Visual reference
About these practice questions
This C100DBA question is part of Courseiva's 222-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam 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 C100DBA 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 C100DBA exam.