A compound index improves search performance by indexing multiple fields.
Query to Create a Compound Index:
db.products.createIndex({ category: 1, price: -1 })
Example Search Using the Index:
db.products.find({ category: "Electronics" }).sort({ price: -1 })