title: Mongoosejs text index an object
body: <p>currently im having a problem regarding referencing text index in object
  here's the code</p>
  
  <p>Schema</p>
  
  <pre><code>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);
  </code></pre>
  
  <p>API</p>
  
  <pre><code>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);
      });
  });
  </code></pre>
  
  <p>As you can see here "supplierdetails" is an object on my schema, and i tell mongoosejs to text index it, because i want to do a text index search on the whole supplierdetails object which contains name, businesstype, products, location and etc.., i saw on my mongo shell the created index
  <a href="https://i.stack.imgur.com/eeXgt.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/eeXgt.jpg" alt="enter image description here"></a></p>
  
  <p>But it's still not working
  This is my data on database</p>
  
  <p><a href="https://i.stack.imgur.com/kftPv.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/kftPv.jpg" alt="enter image description here"></a></p>
  
  <p>I searched "dog" or "shiba" but still returning me no results.</p>
  
  <p>My other functionality which uses text index is perfectly working, the only difference is, the one that i've text index isn't an object, it's just a String property and it perfectly works</p>
  
  <p>Am i doing it wrong?</p>