MongoDB Documentation, Release 3.0.4 The query returns the following documents: To support the query, add a compound index (page 489). With compound indexes (page 489), the order of the fields matter. For example, add the following two compound indexes. The first index orders by quantity field first, and then the type field. The second index orders by type first, and then the quantity field. Evaluate the effect of the first index on the query: db.inventory.find( { quantity: { $gte: 100, $lte: 300 }, type: "food" } ).hint({ quantity: 1, type: 1 }).explain("executionStats") { "queryPlanner" : { ... "winningPlan" : { "stage" : "FETCH", "inputStage" : { "stage" : "IXSCAN", "keyPattern" : { "quantity" : 1, "type" : 1 }, ... } } }, "rejectedPlans" : [ ] }, "executionStats" : { "executionSuccess" : true , "nReturned" : 2, "executionTimeMillis" : 0, "totalKeysExamined" : 5, "totalDocsExamined" : 2, "executionStages" : { ... } }, ... } The explain() method returns the following output: MongoDB scanned 5 index keys ( executionStats.totalKeysExamined ) to return 2 matching documents ( executionStats.nReturned ). Evaluate the effect of the second index on the query: Chapter 3. MongoDB CRUD Operations 114 db.inventory.find( { quantity: { $gte: 100, $lte: 300 }, type: "food" } ) { "_id" : 2, "item" : "f2", "type" : "food", "quantity" : 100 } { "_id" : 5, "item" : "f3", "type" : "food", "quantity" : 300 } db.inventory.createIndex( { quantity: 1, type: 1 } ) db.inventory.createIndex( { type: 1, quantity: 1 } )