我在(访问者)的子对象中记录网站使用事件。这里是数据结构的基本例子:在MongoDB中查询子对象不使用索引
{ "_id" : ObjectId("4d4c695794b332a0740009bd"), "evs" : [
{
"ev" : "Visit Home Page",
"d" : 1,
"s" : 1
},
{
"ev" : "Buy Product",
"d" : "110.10",
"upc" : 1234,
"s" : 1
},
{
"ev" : "Sign up to newsletter",
"d" : "1",
"s" : 1
}
]}
我有“evs.s”的指数,但是当我上evs.s搜索,索引不使用:
db.visitors.find({'evs.s':0}).explain()
{
"cursor" : "BtreeCursor evs.s_1",
"nscanned" : 33361,
"nscannedObjects" : 33361,
"n" : 33361,
"millis" : 311,
"nYields" : 105,
"nChunkSkips" : 0,
"isMultiKey" : false,
"indexOnly" : false,
"indexBounds" : {
"evs.s" : [
[
0,
0
]
]
}
}
该查询需要311毫秒并扫描每个对象。
这里是指数:db.visitors.getIndexes()
{
"ns" : "tracking.visitors",
"unique" : false,
"key" : {
"evs.s" : 1
},
"name" : "evs.s_1",
"v" : 0
}
Ahhhhh是的你的权利,没有真正的方法来有效地索引10,000 0的。限制大大加快查询速度,谢谢! – Lerchmo 2011-02-06 16:11:13