Firstly, Start the mongod process with command line options
--setParameter textSearchEnabled=true
Example:
mongod --setParameter textSearchEnabled=true
Then in your mongo shell, create an index for name in tag collection
db.tag.ensureIndex({name : "text"});
Now you can query using text:
db.tag.runCommand("text", {search : "star wars episode"});
This will return you something like this
{
"queryDebugString" : "star||||||",
"language" : "english",
"results" : [
{
"score" : 1.1,
"obj" : {
"_id" : ObjectId("536f7107c55b2acc61000bc8"),
"name" : "star"
}
},
{
"score" : 0.75,
"obj" : {
"_id" : ObjectId("536f710fc55b2acc61000bc9"),
"name" : "star wars"
}
}
],
"stats" : {
"nscanned" : 2,
"nscannedObjects" : 0,
"n" : 2,
"nfound" : 2,
"timeMicros" : 152
},
"ok" : 1
}
To get only the results:
db.tag.runCommand("text", {search : "star wars episode"}).results
I have tested it with my local DB and it works fine. please check it
For more info about text : Mongo DOCs
BTW from mongoDB 2.6: DOCS
db.tag.find({$text : {$search : "star wars episode VII"}});