title: MongoDB text search on subdocuments with unknown structure
body: <p>I have a collection of documents, each one with a nested document as the ones named "attributes" in this example:</p>
  
  <pre><code>document1: {
      description: 'text text etc',
      attributes: {
          Name: 'Alice',
          Height: '170',
          FavouriteColour: 'Blue'
      }
  }
  
  document2: {
      description: 'more text etc',
      attributes: {
          Name: 'Bob',
          State: 'NY'
      }
  }
  </code></pre>
  
  <p>I don't know what are the names of the keys as they are user-defined. </p>
  
  <p>I want to perform a text search on the values of all attributes in that document without having to specify the keys but in order to perform the text search I need exactly one text index for the <a href="http://docs.mongodb.org/manual/core/index-text/" rel="nofollow">$text</a> query, so this is not possible:</p>
  
  <pre><code>db.collection.aggregate([
      {$match: {$text: {$search: 'NY'}}},
      {$group: {_id: {$meta: "textScore"}, count: {$sum: 1}}}
  ])
  </code></pre>
  
  <p>Since I don't know what attributes I might have, is there a way to work around this and perform a text search on the attributes values and return documents that match the input?</p>