Challenge - 5 Problems
Index Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate2:00remaining
Find queries missing indexes from system.profile
Given the
system.profile collection in MongoDB that logs slow queries, which query will return all queries that did NOT use an index?MongoDB
db.system.profile.find({ 'planSummary': 'COLLSCAN' })Attempts:
2 left
💡 Hint
Look for queries that performed a collection scan instead of using an index.
✗ Incorrect
Queries that do not use an index show 'COLLSCAN' in the planSummary field. Filtering for this value returns queries missing indexes.
🧠 Conceptual
intermediate1:30remaining
Why missing indexes cause slow queries
Why do missing indexes cause queries to be slow in MongoDB?
Attempts:
2 left
💡 Hint
Think about how MongoDB finds data without an index.
✗ Incorrect
Without an index, MongoDB performs a collection scan, checking every document, which is slower than using an index.
📝 Syntax
advanced2:30remaining
Identify the correct aggregation to find missing indexes
Which aggregation pipeline correctly counts how many queries used collection scans (missing indexes) grouped by namespace?
MongoDB
db.system.profile.aggregate([ { $match: { planSummary: 'COLLSCAN' } }, { $group: { _id: '$ns', count: { $sum: 1 } } } ])Attempts:
2 left
💡 Hint
Match first, then group to count per namespace.
✗ Incorrect
The pipeline first filters queries with 'COLLSCAN' then groups by namespace to count them. Changing order or condition breaks logic.
🔧 Debug
advanced2:00remaining
Why does this query not find missing indexes?
This query returns zero results but there are slow queries without indexes. Why?
db.system.profile.find({ planSummary: { $eq: 'COLLSCAN' } })Attempts:
2 left
💡 Hint
Check if profiling is enabled to log slow queries.
✗ Incorrect
If profiling is off or set to a level that does not log slow queries, system.profile will be empty, so no results are found.
❓ optimization
expert3:00remaining
Optimize index usage for frequent queries
You have many slow queries scanning the
orders collection filtering by customerId and sorting by orderDate. Which index will best improve performance?Attempts:
2 left
💡 Hint
Index fields should match the query filter first, then the sort order.
✗ Incorrect
An index starting with customerId supports filtering, then orderDate supports sorting efficiently. The order of fields matters.