mongodb查询应包含在索引中,但不包含在索引中
查询:mongodb查询应包含在索引中,但不包含在索引中,mongodb,compound-index,Mongodb,Compound Index,查询: db.myColl.find({“M.ST”:“mostrepresentedvalueinthecollection”,“M.TS”:新日期(2014,2,1)})。explain() 解释输出: "cursor" : "BtreeCursor M.ST_1_M.TS_1", "isMultiKey" : false, "n" : 587606, "nscannedObjects" : 587606, "nscanned"
db.myColl.find({“M.ST”:“mostrepresentedvalueinthecollection”,“M.TS”:新日期(2014,2,1)})。explain()
解释输出:
"cursor" : "BtreeCursor M.ST_1_M.TS_1",
"isMultiKey" : false,
"n" : 587606,
"nscannedObjects" : 587606,
"nscanned" : 587606,
"nscannedObjectsAllPlans" : 587606,
"nscannedAllPlans" : 587606,
"scanAndOrder" : false,
"indexOnly" : false,
"nYields" : 9992,
"nChunkSkips" : 0,
"millis" : 174820,
"indexBounds" : {
"M.ST" : [
[
"mostrepresentedvalueinthecollection",
"mostrepresentedvalueinthecollection"
]
],
"M.TS" : [
[
ISODate("2014-03-01T00:00:00Z"),
ISODate("2014-03-01T00:00:00Z")
]
]
},
"server" : "myServer"
其他详细信息:myColl包含约4000万个文档,平均对象大小为300b
我不明白为什么indexOnly没有设置为true,我在{“M.ST”:1,“M.TS”:1}上有一个复合索引
mongo主机是一个unix机箱,具有16gb RAM和500gb磁盘空间(旋转磁盘)。
数据库的总索引大小是10gb,大约1k upserts/sec,在这1k上20个是插入,其余是增量
我们还有另一个查询,它在find查询中添加了第三个字段(称为“M.X”),还有一个关于“M.ST”、“M.X”、“M.TS”的复合索引。这一个是闪电般的快,只扫描330份文件
你知道会出什么问题吗
谢谢
编辑:以下是示例文档的结构:
{
"_id" : "somestring",
"D" : {
"20140301" : {
"IM" : {
"CT" : 143
}
},
"20140302" : {
"IM" : {
"CT" : 44
}
},
"20140303" : {
"IM" : {
"CT" : 206
}
},
"20140314" : {
"IM" : {
"CT" : 5
}
}
},
"Y" : "someotherstring",
"IM" : {
"CT" : 1
},
"M" : {
"X" : 99999,
"ST" : "mostrepresentedvalueinthecollection",
"TS" : ISODate("2014-03-01T00:00:00.000Z")
},
}
其思想是按月存储一些分析指标,“D”字段表示一个包含当月每天数据的文档数组。我认为您需要对该查询设置一个投影,以告诉mongo它包含哪些索引 试试这个
db.myColl.find({"M.ST": "mostrepresentedvalueinthecollection", "M.TS": new Date(2014,2,1)},{ M.ST:1, M.TS:1, _id:0 }).explain()
编辑:
此功能当前未实现。相应的JIRA票是。您可以投票支持它,但现在,要利用覆盖索引查询,您需要避免使用点符号/嵌入文档。感谢您的建议,这是有意义的,但没有意义。索引仍然没有涵盖mongo,我认为mongo还不支持覆盖索引中的dotnotation。你能编辑你的问题并分享你收集的样本文档的结构吗?@LaurentH,你是对的。此功能尚未在MongoDB中实现。我编辑了我的答案。和我给Anan的答案一样。。。无论如何,谢谢你。