1
我想在貓鼬中使用`$文本,但它總是向我顯示錯誤。
模型/方案:
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);
}
});
它總是顯示我的錯誤。
我想搜索的用戶ID,我已經指定索引:在架構 –
真@MohammedGadiwala,嘗試使用'thSchema2.index({'userid':'text'});','index:true'與文本索引不同。 – zangw
@MohammedGadiwala,這裏有一個關於貓鼬的文本索引的討論,https://github.com/Automattic/mongoose/issues/1401 – zangw