我希望通过两个值来查询mongodb集合:
我希望为要查询的creationTime参数提供一系列值:
{"$and":[
{"creationTime":{"$gt":"TIME_START"}},
{"creationTime":{"$lt":"TIME_END"}},
{"restaurantId":"ID_STRING"},
]}
此集合有两个索引:
{
"restaurantId" : 1,
"creationTime" : 1
}
{
"creationTime" : 1
}
db.Meal.stats()
{
"ns" : "waiterio_database.Meal",
"count" : 472855,
"size" : 1022141200,
"avgObjSize" : 2161.637711349145,
"storageSize" : 1180352512,
"numExtents" : 16,
"nindexes" : 3,
"lastExtentSize" : 316321792,
"paddingFactor" : 1.1150000000386548,
"systemFlags" : 1,
"userFlags" : 0,
"totalIndexSize" : 102567920,
"indexSizes" : {
"id" : 30586416,
"restaurantId_1_creationTime_1" : 49939008,
"creationTime_1" : 22042496
},
"ok" : 1
}
复合查询说明()
{
"cursor":"BtreeCursor restaurantId_1_creationTime_1",
"isMultiKey":false,
"n":100,
"nscannedObjects":100,
"nscanned":100,
"nscannedObjectsAllPlans":100,
"nscannedAllPlans":100,
"scanAndOrder":false,
"indexOnly":false,
"nYields":0,
"nChunkSkips":0,
"millis":0,
"indexBounds":{
"restaurantId":[
[
"51af5b90e4b03c3d231ee0c5",
"51af5b90e4b03c3d231ee0c5"
]
],
"creationTime":[
[
1435708800000,
1.7976931348623157E308
]
]
},
"allPlans":[
{
"cursor":"BtreeCursor restaurantId_1_creationTime_1",
"n":100,
"nscannedObjects":100,
"nscanned":100,
"indexBounds":{
"restaurantId":[
[
"51af5b90e4b03c3d231ee0c5",
"51af5b90e4b03c3d231ee0c5"
]
],
"creationTime":[
[
1435708800000,
1.7976931348623157E308
]
]
}
}
],
"oldPlan":{
"cursor":"BtreeCursor restaurantId_1_creationTime_1",
"indexBounds":{
"restaurantId":[
[
"51af5b90e4b03c3d231ee0c5",
"51af5b90e4b03c3d231ee0c5"
]
],
"creationTime":[
[
1435708800000,
1.7976931348623157E308
]
]
}
},
"server":"SERVER_HOST"
}
数据库托管在Mongolab上,它报告平均查询需要更长的时间,并且它建议索引(即使我已经设置了这两个)。 Mongolab仪表板建议:不支持的查询模式
知道如何设置可以使用这种查询的集合的索引吗?
(mongod版本:2.4.10)