> db.foo.insert({a:1,b:"hello"})
|
WriteResult({ "nInserted" : 1 })
|
> db.foo.ensureIndex({b:"text",a:1})
|
WriteResult({ "nInserted" : 1 })
|
> db.foo.find({a:1,$text:{$search:"hello"}},{_id:0,a:1}).explain()
|
{
|
"cursor" : "TextCursor",
|
"n" : 1,
|
"nscannedObjects" : 0, // Good: text index correctly covers this query
|
"nscanned" : 1,
|
"nscannedObjectsAllPlans" : 0,
|
"nscannedAllPlans" : 1,
|
"scanAndOrder" : false,
|
"nYields" : 0,
|
"nChunkSkips" : 0,
|
"millis" : 0,
|
"server" : "Rassi-MacBook-Pro.local:27017",
|
"filterSet" : false
|
}
|
> db.foo.dropIndexes()
|
{
|
"nIndexesWas" : 2,
|
"msg" : "non-_id indexes dropped for collection",
|
"ok" : 1
|
}
|
> db.foo.ensureIndex({a:1,b:"text"})
|
WriteResult({ "nInserted" : 1 })
|
> db.foo.find({a:1,$text:{$search:"hello"}},{_id:0,a:1}).explain()
|
{
|
"cursor" : "TextCursor",
|
"n" : 1,
|
"nscannedObjects" : 1, // Bad: text index should be able to cover this query
|
"nscanned" : 1,
|
"nscannedObjectsAllPlans" : 1,
|
"nscannedAllPlans" : 1,
|
"scanAndOrder" : false,
|
"nYields" : 0,
|
"nChunkSkips" : 0,
|
"millis" : 0,
|
"server" : "Rassi-MacBook-Pro.local:27017",
|
"filterSet" : false
|
}
|
>
|
This type of query is "coverable" (nscannedObjects=0) with the text command in version 2.4.
|