Index fields used together in filters or sorts.
Section: Create indexes
Create a compound index
javascript
javascript
db.orders.createIndex({ status: 1, created_at: -1 })Explanation
Compound indexes are useful when queries filter and sort on a predictable pattern.
Learn the surrounding workflow
Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.
Related commands
Same sheet · prioritizing Create indexes
Enforce uniqueness with an index
Prevent duplicate values at write time.
Force a specific index with hint
Test how a query behaves with a chosen index.