Mongoose $文本字段错误

我正在尝试在mongoose中使用`$ text,但是它总是向我显示错误。

模型/scheme:

var thSchema2=new Schema({ userid:{ type: String, unique: true,index: true}, password:String, name:String, phone:String }); 

我在控制器中的查询:

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

它总是向我显示错误。

如果您希望search字段name ,那么您缺less架构中的文本索引,然后像下面那样添加文本索引

 thSchema2.index({'name': 'text'});