Reputation: 2063
I am trying to use `$text in mongoose but it's always showing me the error.
Model/Schema:
var thSchema2=new Schema({
userid:{ type: String, unique: true,index: true},
password:String,
name:String,
phone:String
});
My query in the controller:
Model
.find( { $text : { $search : "mo"} })
.exec(function(err, results) {
if(err){
console.log("eroro ocured");
res.send(401);
}else{
console.log("foud");
res.json(results);
}
});
It's always showing me error.
Upvotes: 1
Views: 125
Reputation: 48436
You missing text
index in your schema, if you want the search the field name
, then add text index as below
thSchema2.index({'name': 'text'});
Upvotes: 2