Sequence NODE_274
MediumUse Compound Index for Query Optimization
MongoDB
Technical Specification
Create a compound index on products price and category to speed up queries filtering both.
Input/Output Samples
Input:find { category:'books', price: { $gt: 500 } }
Output:Uses compound index
Optimal Logic Path
db.products.createIndex({ category: 1, price: 1 });
// query using both:
db.products.find({ category: "books", price: { $gt: 500 } });Architectural Deep-Dive
Compound indexes are designed to serve queries that filter/sort by multiple fields together.