Database Reference
In-Depth Information
You can see in the queryDebugString that each element was evaluated and queried against. You can also see that
this query evaluated and found two documents. Now notice the difference when we run the same query with escaped
quote marks to make it a string literal:
> db.texttest.runCommand( "text", { search : "\"mongodb text search\"" })
{
"queryDebugString" : "mongodb|search|text||||mongodb text search||",
"language" : "english",
"results" : [
{
"score" : 3.875,
"obj" : {
"_id" : ObjectId("51d7ccb36bc6f959debe551a"),
"number" : 7,
"body" : "i like mongodb text search",
"about" : "food"
}
}
],
"stats" : {
"nscanned" : 6,
"nscannedObjects" : 0,
"n" : 1,
"nfound" : 1,
"timeMicros" : 134
},
"ok" : 1
}
You can see that only one document is returned, the document that actually contains the text in question. You
can also see that in the queryDebugString the final element is the string itself rather than just the three tokenized and
stemmed elements.
Additional Options
In addition to those we have discussed so far, there are three other options you can add into the text function. The
first is limit , which limits the number of documents returned. It can be used as follows:
> db.texttest.runCommand( "text", { search :"fish", limit : 1 } )
The second option is project , which allows you to set the fields that will be displayed as the result of the query.
This option takes a document describing which fields you wish to display, with 0 being off and 1 being on. By default
when specifying this option all elements are off except for _id , which is on.
> db.texttest.runCommand( "text", { search :"fish", project : { _id : 0, body : 1 } } )
The third and final option is language , which allows you to specify which language the text search will use. If no
language is specified, then the index's default language is used. The language must be specified all in lower case. It
can be invoked as follows:
> db.texttest.runCommand( "text", { search :"fish", lagnuage : "french" } )
 
Search WWH ::




Custom Search