I mongo 2.6+ $text
fungerer som følger:
db.collection.insert({desc: "This is a string with text"});
db.collection.insert({desc:"This is a another string with Text"});
db.collection.insert({desc:"This is a another string with ext"});
db.collection.ensureIndex({"desc":"text"});
db.collection.find({
$text:{
$search:"text"
}
});
Dette vil give output som:
{ "_id" : ObjectId("553277a608b85f33165bf3e0"),
"desc" : "This is a another string with Text" }
{ "_id" : ObjectId("5532779f08b85f33165bf3df"),
"desc" : "This is a string with text" }
Også hvis du bruger mongo version 2.4, så brug følgende:
db.collection.ensureIndex({"desc":"text"});
db.collection.runCommand( "desc", { search: "Text"})