Create compound index mongodb

Ascending userId + descending createdAt index

db.orders.createIndex({userId: 1, createdAt: -1}, {background: true})
more mongodb all 20 commands →