我试图在 Mongoose 中使用`$text,但它总是向我显示错误。
模型/架构:
var thSchema2=new Schema({
userid:{ type: String, unique: true,index: true},
password:String,
name:String,
phone:String
});
我在 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);
}
});
它总是向我显示错误。
最佳答案
您的架构中缺少text
索引,如果您想要搜索字段name
,请添加如下文本索引
thSchema2.index({'name': 'text'});
关于node.js - Mongoose $text 字段错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36005381/