2
我有一個帶有'name'索引的集合。如何強制mongodb使用BasicCursor而不是索引
> db.search.getIndexes()
[
{
"v" : 1,
"key" : {
"_id" : 1
},
"name" : "_id_"
},
{
"v" : 1,
"key" : {
"name" : 1
},
"name" : "name_1"
}
]
>
我的一個疑問是
> db.collection.find({name: {$regex: '^string'}}).explain()
,並使用該索引
{
"cursor" : "BtreeCursor name_1 multi",
"isMultiKey" : false,
"n" : 25,
"nscannedObjects" : 25,
"nscanned" : 3247,
"nscannedObjectsAllPlans" : 25,
"nscannedAllPlans" : 3247,
"scanAndOrder" : false,
"indexOnly" : false,
"nYields" : 0,
"nChunkSkips" : 0,
"millis" : 366,
"indexBounds" : {
"name" : [
[
"",
{
}
],
[
/string/,
/string/
]
]
},
"server" : "..."
}
我已經知道從MongoDB regular expression with indexed field,使用BasiCursor會更快。
> db.search.find({name: {$regex: 'string'}}).explain()
{
"cursor" : "BasicCursor",
"isMultiKey" : false,
"n" : 27,
"nscannedObjects" : 3385,
"nscanned" : 3385,
"nscannedObjectsAllPlans" : 3385,
"nscannedAllPlans" : 3385,
"scanAndOrder" : false,
"indexOnly" : false,
"nYields" : 0,
"nChunkSkips" : 0,
"millis" : 20,
"indexBounds" : {
},
}
如何告訴Mongodb在不刪除索引的情況下使用BasicCursor?
的[$提示操作(http://docs.mongodb.org/manual/reference/operator/hint /)可以用來強制使用特定的索引。也許它也可以通過傳遞一個空對象來強制索引被忽略? – Philipp 2013-04-30 21:43:09