が現在のオブジェクトここ で参照するテキストインデックスに関する問題を持つイムオブジェクトは、「supplierdetailsコードMongoosejsテキストインデックス
スキーマ
var UserSchema = new mongoose.Schema({
username: String,
fullname: String,
email: {
type: String,
lowercase: true,
unique: true
},
supplier: Boolean,
supplierdetails: {
name: String,
businesstype: String,
location: String,
products: String,
revenue: String,
employees: String,
yearsestablished: String
}
});
UserSchema.index({supplierdetails: 'text'});
module.exports = mongoose.model('User', UserSchema);
API
router.post('/findsupplier', function(req, res){
User.find({supplier: true, $text: {$search: req.body.supplyData}}, {score: {$meta: 'textScore'}})
.sort({score: {$meta: 'textScore'}})
.exec(function(err, supplyResult){
if(err)
throw err;
else
res.json(supplyResult);
});
});
あなたがここに見ることができるようです"私のスキーマ上のオブジェクトであり、私はmongoosejsにテキスト索引付けを指示します。これは、namを含むsupplierdetailsオブジェクト全体でテキスト索引検索を実行したいからですE、businessTypeです、製品、場所、など。、私が作成したインデックス
シェル私のモンゴで見た。しかし、それはまだ を働いていないこれは私が検索データベース
に私のデータであります"犬"または "芝"しかし、私はまだ結果を返しません。テキストインデックスを使用しています
私の他の機能が完全に働いている、唯一の違いは、私は、テキストインデックスをした1がオブジェクトではありませんが、それだけでStringプロパティだと、それは完全に
を働く私がやっていますそれは間違っている?
_shiba_は 'req.body.supplyData'で送信されますか? – Dash
はい。私はconsole.logにしようとし、それが表示されます – John