2017-05-16 14 views
0

が現在のオブジェクトここ で参照するテキストインデックスに関する問題を持つイムオブジェクトは、「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です、製品、場所、など。、私が作成したインデックス enter image description here

シェル私のモンゴで見た。しかし、それはまだ を働いていないこれは私が検索データベース

enter image description here

に私のデータであります"犬"または "芝"しかし、私はまだ結果を返しません。テキストインデックスを使用しています

私の他の機能が完全に働いている、唯一の違いは、私は、テキストインデックスをした1がオブジェクトではありませんが、それだけでStringプロパティだと、それは完全に

を働く私がやっていますそれは間違っている?

+0

_shiba_は 'req.body.supplyData'で送信されますか? – Dash

+0

はい。私はconsole.logにしようとし、それが表示されます – John

答えて

0

documentationによれば、文字列または文字列配列にテキストインデックスを作成できますが、オブジェクト(文字列を含む)は作成できません。

関連する問題