我想在猫鼬字符串数组上进行全文搜索,我得到这个错误:全文搜索与猫鼬
{ [MongoError: text index required for $text query]
name: 'MongoError',
message: 'text index required for $text query',
waitedMS: 0,
ok: 0,
errmsg: 'text index required for $text query',
code: 27 }
不过,我有一个文本索引宣布对用户架构的领域,我证实了,因为我使用MLAB文本索引已创建。 我想执行的领域
这里全文搜索我的用户模式:
var userSchema = mongoose.Schema({
local: {
firstName: String,
lastName: String,
username: String,
password: String,
fields: {type: [String], index: true}
}
});
这里是我的全文搜索代码:
User.find({$text: {$search: search}}, function (err, results) {
if (err) {
console.log(err);
} else {
console.log(results);
}
});
您正在使用哪个版本mogoose? – Mitchapp
目前使用的猫鼬4.7.0 – Jasch1
你需要在你的领域创建文本索引:[示例](https://docs.mongodb.com/manual/reference/operator/query/text/#examples) –