0
0
MongoDBquery~20 mins

Identifying missing indexes in MongoDB - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Index Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2: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' })
Adb.system.profile.find({ 'planSummary': 'COLLSCAN' })
Bdb.system.profile.find({ 'planSummary': { $ne: 'COLLSCAN' } })
Cdb.system.profile.find({ 'planSummary': 'IXSCAN' })
Ddb.system.profile.find({ 'planSummary': { $exists: false } })
Attempts:
2 left
💡 Hint
Look for queries that performed a collection scan instead of using an index.
🧠 Conceptual
intermediate
1:30remaining
Why missing indexes cause slow queries
Why do missing indexes cause queries to be slow in MongoDB?
ABecause missing indexes cause MongoDB to create temporary indexes automatically.
BBecause MongoDB caches all queries without indexes.
CBecause missing indexes cause MongoDB to lock the entire database.
DBecause MongoDB must scan every document in the collection to find matches.
Attempts:
2 left
💡 Hint
Think about how MongoDB finds data without an index.
📝 Syntax
advanced
2: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 } } } ])
Adb.system.profile.aggregate([ { $match: { planSummary: { $ne: 'COLLSCAN' } } }, { $group: { _id: '$ns', count: { $sum: 1 } } } ])
Bdb.system.profile.aggregate([ { $match: { planSummary: 'COLLSCAN' } }, { $group: { _id: '$ns', count: { $sum: 1 } } } ])
Cdb.system.profile.aggregate([ { $group: { _id: '$ns', count: { $sum: 1 } } }, { $match: { planSummary: 'COLLSCAN' } } ])
Ddb.system.profile.aggregate([ { $match: { planSummary: 'IXSCAN' } }, { $group: { _id: '$ns', count: { $sum: 1 } } } ])
Attempts:
2 left
💡 Hint
Match first, then group to count per namespace.
🔧 Debug
advanced
2: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' } })
ABecause the system.profile collection is not enabled or profiling level is too low.
BBecause the planSummary field sometimes contains 'COLLSCAN' inside an array, so $eq fails.
CBecause the field name is case sensitive and should be 'planSummary' exactly.
DBecause $eq operator is not supported in MongoDB queries.
Attempts:
2 left
💡 Hint
Check if profiling is enabled to log slow queries.
optimization
expert
3: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?
A{ customerId: 1 }
B{ orderDate: -1, customerId: 1 }
C{ customerId: 1, orderDate: -1 }
D{ orderDate: 1 }
Attempts:
2 left
💡 Hint
Index fields should match the query filter first, then the sort order.