Skip to main content
Journey Uncommon Logo
JourneyUncommon
mediumMongoDBmultikey array indexesSingle-choice MCQ

You want to index a field that is an array of subdocuments, and frequently query on two fields of the same subdocument together (e.g. items with a specific name AND price). Which index design correctly supports matching both conditions within the SAME array element?

db.orders.createIndex({ "items.name": 1, "items.price": 1 }) db.orders.find({ items: { $elemMatch: { name: "pen", price: { $lt: 5 } } } })