I've created an index with this:
db.MyCollection.ensureIndex({"field1": "text"})
and I'm running the following in Robomongo:
db.MyCollection.find({$text:{$search:"something"}})
and getting back this error:
error: { "$err" : "invalid operator: $search", "code" : 10068 }
The docs seem to be pretty clear that I'm using the correct syntax: http://docs.mongodb.org/manual/reference/operator/query/text/ . I'm using mongo version 2.4.9. Anyone know what the problem could be here?
$search. string. A string of terms that MongoDB parses and uses to query the text index. MongoDB performs a logical OR search of the terms unless specified as a phrase. See Behavior for more information on the field.
Use the $text query operator to perform text searches on a collection with a text index. $text will tokenize the search string using whitespace and most punctuation as delimiters, and perform a logical OR of all such tokens in the search string.
Explanation: MongoDB supports search by field, range queries, regular expression searches.
MongoDB text search uses the Snowball stemming library to reduce words to an expected root form (or stem) based on common language rules. Algorithmic stemming provides a quick reduction, but languages have exceptions (such as irregular or contradicting verb conjugation patterns) that can affect accuracy.
In mongo 2.6+ $text
works as follows:
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"
}
});
This will gives output as :
{ "_id" : ObjectId("553277a608b85f33165bf3e0"),
"desc" : "This is a another string with Text" }
{ "_id" : ObjectId("5532779f08b85f33165bf3df"),
"desc" : "This is a string with text" }
Also if you are using mongo version 2.4 then use following:
db.collection.ensureIndex({"desc":"text"});
db.collection.runCommand( "desc", { search: "Text"})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With