This example inserts three users, creates an index on the email field, then finds the user with email 'bob@example.com'. The index helps MongoDB find Bob quickly.
Which statement is true about the executionStats output?
medium
A. The query will show a COLLSCAN stage indicating a full collection scan.
B. The query will show an IXSCAN stage indicating an index scan on email.
C. The query will fail because explain cannot be used with find.
D. The query will show no stages because indexes are ignored.
Solution
Step 1: Understand explain with executionStats
Explain with 'executionStats' shows how MongoDB executes the query, including index usage.
Step 2: Effect of index on email field
Since there is an index on email, MongoDB uses an index scan (IXSCAN) instead of a full collection scan (COLLSCAN).
Final Answer:
The query will show an IXSCAN stage indicating an index scan on email. -> Option B
Quick Check:
Index present means IXSCAN used = D [OK]
Hint: Explain shows IXSCAN if index used, COLLSCAN if not [OK]
Common Mistakes:
Confusing COLLSCAN with IXSCAN
Thinking explain causes query failure
Assuming indexes are ignored in explain
4. You created an index on age field but your queries still perform full collection scans. What is the most likely reason?
medium
A. MongoDB does not support indexes on numeric fields.
B. Indexes slow down queries intentionally.
C. The index was created with the wrong field name or syntax error.
D. You must restart MongoDB to activate indexes.
Solution
Step 1: Check index creation correctness
If the index was created with a wrong field name or syntax error, it won't be used by queries.
Step 2: Eliminate other options
MongoDB supports numeric indexes, does not require restart, and indexes speed up queries, not slow them.
Final Answer:
The index was created with the wrong field name or syntax error. -> Option C
Quick Check:
Incorrect index creation causes no index use = B [OK]
Hint: Check index field names and syntax if queries ignore indexes [OK]
Common Mistakes:
Believing MongoDB needs restart for indexes
Thinking numeric fields can't be indexed
Assuming indexes slow queries
5. You have a large collection with frequent writes and queries on status and createdAt. How should you design indexes to balance read speed and write performance?
hard
A. Create a compound index on {status: 1, createdAt: -1} and avoid extra indexes.
B. Create separate indexes on status and createdAt and many others for all queries.
C. Create no indexes to keep writes fast.
D. Create an index on a non-used field to reduce write load.
Solution
Step 1: Understand compound indexes for multiple query fields
A compound index on {status: 1, createdAt: -1} supports queries filtering by status and sorting by createdAt efficiently.
Step 2: Balance index count for write performance
Too many indexes slow writes. Using one compound index reduces overhead while improving read speed.
Final Answer:
Create a compound index on {status: 1, createdAt: -1} and avoid extra indexes. -> Option A
Quick Check:
Compound index balances reads and writes = A [OK]
Hint: Use compound indexes for multi-field queries, limit total indexes [OK]
Common Mistakes:
Creating too many indexes hurting write speed
Not using compound indexes for related fields
Avoiding indexes completely hurting read speed
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.