MongoDB 8 · Indexes and performance
Create a compound index
Index two fields together, in the order you filter and sort by them.
db.orders.createIndex({ userId: 1, createdAt: -1 })
Official MongoDB 8 documentation
MongoDB 8 · Indexes and performance
Index two fields together, in the order you filter and sort by them.
db.orders.createIndex({ userId: 1, createdAt: -1 })
Official MongoDB 8 documentation
Was this page helpful?