我有以下查询:
db.restaurant_service_orders.find({order_settlement_status :1,order_status : {"$in" : [6,4]}, created_at : {"$lte" : ISODate("2015-04-10T00:00:00.000Z"), "$gte" : ISODate("2015-03-10T00:00:00.000Z")}})
我创建了以下索引:
index({created_at:1 }),
index({order_settlement_status: 1, order_status: 1, created_at: 1})
但在query.explain()
我在created_at上获得索引而不在我的其他索引上。
请为上述建议适当的指标,并解释原因:
解释计划:
db.restaurant_service_orders.find({order_settlement_status :1,order_status : {"$in" : [6,4]}, created_at : {"$lte" : ISODate("2015-04-10T00:00:00.000Z"), "$gte" : ISODate("2014-03-10T00:00:00.000Z")}}).explain()
{"光标" :" BtreeCursor created_at_1"," isMultiKey" :false," n" :182222," nscannedObjects" :209645," nscanned" :209645, " nscannedObjectsAllPlans" :210453," nscannedAllPlans" :210756, " scanAndOrder" :false," indexOnly" :false," nYields" :0, " nChunkSkips" :0," millis" :815," indexBounds" :{" created_at" :[[ ISODate(" 2014-03-10T00:00:00Z&#34), ISODate(" 2015-04-10T00:00:00Z")]]},"服务器" :" Junaids-MacBook-Pro.local:27017" }
提示的解释计划:
db.restaurant_service_orders.find({order_settlement_status :1,order_status : {"$in" : [6,4]}, created_at : {"$lte" : ISODate("2015-04-10T00:00:00.000Z"), "$gte" : ISODate("2014-03-10T00:00:00.000Z")}}).hint({order_settlement_status :1,order_status : 1, created_at : 1}).explain()
{"光标" :" BtreeCursor order_settlement_status_1_order_status_1_created_at_1 multi", " isMultiKey" :false," n" :182222," nscannedObjects" :182222, " nscanned" :182223," nscannedObjectsAllPlans" :182222, " nscannedAllPlans" :182223," scanAndOrder" :false," indexOnly" : false," nYields" :2," nChunkSkips" :0," millis" :540, " indexBounds" :{" order_settlement_status" :[[ 1, 1]]," order_status" :[[ 4, 4],[ 6, 6]]," created_at" :[[ ISODate(" 2014-03-10T00:00:00Z&#34), ISODate(" 2015-04-10T00:00:00Z")]]},"服务器" :" Junaids-MacBook-Pro.local:27017" }