0
0
MongoDBquery~20 mins

Partial indexes with filter in MongoDB - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Partial Index Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
Effect of Partial Index on Query Performance

Consider a MongoDB collection orders with documents having fields status and total. A partial index is created with filter { status: "completed" } on total. Which query will use this partial index?

MongoDB
db.orders.createIndex({ total: 1 }, { partialFilterExpression: { status: "completed" } })
Adb.orders.find({ status: { $in: ["completed", "pending"] }, total: { $gt: 100 } })
Bdb.orders.find({ status: "pending", total: { $gt: 100 } })
Cdb.orders.find({ total: { $gt: 100 } })
Ddb.orders.find({ status: "completed", total: { $gt: 100 } })
Attempts:
2 left
💡 Hint

Partial indexes only cover documents matching the filter expression.

📝 Syntax
intermediate
2:00remaining
Correct Syntax for Creating a Partial Index

Which of the following commands correctly creates a partial index on the users collection for documents where age is greater than 18?

Adb.users.createIndex({ age: 1 }, { partialFilterExpression: { age: { $gt: 18 } } })
Bdb.users.createIndex({ age: 1 }, { filter: { age: { $gt: 18 } } })
Cdb.users.createIndex({ age: 1 }, { partialFilter: { age: { $gt: 18 } } })
Ddb.users.createIndex({ age: 1 }, { partialFilterExpression: age > 18 })
Attempts:
2 left
💡 Hint

Check the exact option name for partial index filter in MongoDB.

optimization
advanced
2:00remaining
Choosing a Partial Index Filter for Performance

You have a large products collection with a category field. Most queries filter for category: "electronics". Which partial index filter will optimize these queries best?

A{ category: { $ne: null } }
B{ category: { $exists: true } }
C{ category: "electronics" }
D{ category: { $in: ["electronics", "appliances"] } }
Attempts:
2 left
💡 Hint

Partial indexes should match the most common query filter exactly for best performance.

🔧 Debug
advanced
2:00remaining
Why Does This Partial Index Not Improve Query Speed?

A partial index is created on orders with filter { shipped: true }. The query db.orders.find({ shipped: false, total: { $gt: 50 } }) is slow. Why?

AThe query filters for <code>shipped: false</code>, which is not covered by the partial index.
BThe partial index filter is invalid and ignored by MongoDB.
CThe query does not include the <code>total</code> field in the filter.
DPartial indexes cannot be used with boolean fields.
Attempts:
2 left
💡 Hint

Think about which documents the partial index includes.

🧠 Conceptual
expert
2:00remaining
Impact of Partial Indexes on Write Operations

How do partial indexes affect write performance in MongoDB compared to full indexes?

APartial indexes increase write overhead because the filter must be evaluated for every write.
BPartial indexes reduce write overhead because fewer documents need to be indexed.
CPartial indexes have no effect on write performance compared to full indexes.
DPartial indexes cause write operations to fail if documents do not match the filter.
Attempts:
2 left
💡 Hint

Consider how many documents get indexed during writes.