sql >> Base de Datos >  >> NoSQL >> MongoDB

Error de Mongo DB:operador no válido:$buscar al realizar una búsqueda de $texto

En mongo 2.6+ $text funciona de la siguiente manera:

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"
    }
}); 

Esto dará salida como:

{ "_id" : ObjectId("553277a608b85f33165bf3e0"),
 "desc" : "This is a another string with Text" }

{ "_id" : ObjectId("5532779f08b85f33165bf3df"), 
"desc" : "This is a string with text" }

Además, si está utilizando mongo versión 2.4, utilice lo siguiente:

 db.collection.ensureIndex({"desc":"text"});
 db.collection.runCommand( "desc", { search: "Text"})