Given a MongoDB collection products with indexes on category and price, what documents will be returned by this query?
{ category: "electronics", price: { $lt: 100 } }Assume documents:
[{_id:1, category:"electronics", price: 90}, {_id:2, category:"electronics", price: 150}, {_id:3, category:"furniture", price: 80}]db.products.find({ category: "electronics", price: { $lt: 100 } })Think about which documents satisfy both conditions.
The query filters documents where category is "electronics" AND price is less than 100. Only the first document meets both.
What does MongoDB's index intersection feature do?
Think about how MongoDB uses indexes to speed up queries with multiple filters.
Index intersection allows MongoDB to use multiple single-field indexes together to answer queries with multiple conditions efficiently.
Which option correctly creates two single-field indexes on category and price in MongoDB?
Remember how to create single-field indexes separately.
Option C creates two separate single-field indexes, one on category and one on price. Option C creates a compound index. Options B and C use invalid syntax.
You have a query filtering on status and date. You currently have single-field indexes on both fields. Which action will most likely improve query performance?
Think about how compound indexes compare to index intersection.
A compound index on both fields can be more efficient than index intersection because it stores combined keys, reducing the need to merge results.
A query filtering on type and region is slow despite having single-field indexes on both. Which is the most likely cause?
Consider how $or affects index usage.
MongoDB cannot use index intersection for $or queries if the conditions are on different fields in separate clauses. This can cause slower performance.