0
私は奇妙な問題に遭遇し、私はそれを理解することができませんでした。私は、約20のキーとマングースのスキーマを持っていると私はそれらの5に$テキストクエリを使用したいと思い、それは次のようになります。
var mySchema = new mongoose.Schema({
firstkey:{type: String, index: true},
secondkey:{type:String,index: true},
thirdkey:{type:String,index: true},
fourthkey:{type:String,index: true},
fifthkey:{type:String,index: true},
sixth:String,
seventh:String,
.... });
mySchema.index=({'firstkey':'text','secondkey':'text','thirdkey':'text','fourthkey':'text','fifthkey':'text'})
module.exports = mongoose.model("Schema", mySchema);
その後、私のルート・ファイルで、私は次のクエリを実行します。
if (req.query.search) {
Schema.find({ $text: { $search: req.query.search } }, function (err, allRecords) {
if (err) {
console.log(err);
} else {
res.render("records/index", { records: allRecords });
}
});
}
私はフォームに入力した単語がFIRSTKEYで見つけることができる値であり、とにかく場合、私は正しい結果には問題を取得していない、ページ内の検索フォームからreq.query.search
の値を取得しますが、私は入力した場合私の知っている値は、私のクエリが空になる他のキーの1つに存在します。
なぜ$ textがインデックスを作成しようとした他のキーを調べていないのですか?