|
2.4 and 2.6 versions will answer this query using an index scan, e.g.:
> db.version()
|
2.4.11
|
> t.ensureIndex({q: 1})
|
> t.find( { q : /.*cde.*/ } ).explain()
|
{
|
"cursor" : "BtreeCursor q_1 multi",
|
"isMultiKey" : false,
|
"n" : 0,
|
"nscannedObjects" : 0,
|
"nscanned" : 0,
|
"nscannedObjectsAllPlans" : 0,
|
"nscannedAllPlans" : 0,
|
"scanAndOrder" : false,
|
"indexOnly" : false,
|
"nYields" : 0,
|
"nChunkSkips" : 0,
|
"millis" : 0,
|
"indexBounds" : {
|
"q" : [
|
[
|
"",
|
{
|
|
}
|
],
|
[
|
/.*cde.*/,
|
/.*cde.*/
|
]
|
]
|
},
|
"server" : "MacBook-Pro:27017"
|
}
|
With a projection, the plan will be covered:
> t.find( { q : /.*cde.*/ }, { _id: 0, q: 1 } ).explain()
|
{
|
"cursor" : "BtreeCursor q_1 multi",
|
"isMultiKey" : false,
|
"n" : 0,
|
"nscannedObjects" : 0,
|
"nscanned" : 0,
|
"nscannedObjectsAllPlans" : 0,
|
"nscannedAllPlans" : 0,
|
"scanAndOrder" : false,
|
"indexOnly" : true, // Indicates that the plan is covered.
|
"nYields" : 0,
|
"nChunkSkips" : 0,
|
"millis" : 0,
|
"indexBounds" : {
|
"q" : [
|
[
|
"",
|
{
|
|
}
|
],
|
[
|
/.*cde.*/,
|
/.*cde.*/
|
]
|
]
|
},
|
"server" : "MacBook-Pro:27017"
|
}
|
|