title: MongoDB add an index for unknown fields
body: <p>I am using MongoDB to store various types of objects everything is in one collection all objects conform to a similar type. Fields are custom per type of object stored. Field type values can be text, integer, or float.</p>
  
  <pre><code>{
      objectTypeId: x,
      fields: [
          { fieldTypeId: "x1", fieldName: "fieldX1", fieldValue: "x1" },
          { fieldTypeId: "x2", fieldName: "fieldX2", fieldValue: "x2" }
      ]
  }
  
  {
      objectTypeId: y,
      fields: [
          { fieldTypeId: "y1", fieldName: "fieldY1", fieldValue: "y1" },
          { fieldTypeId: "y2", fieldName: "fieldY2", fieldValue: "y2" }
      ]
  }
  </code></pre>
  
  <p>Is there a way to add a generic index that would index all of my field data something like:</p>
  
  <pre><code>db.records.createIndex( { fields.fieldName: field.fieldValue } );
  </code></pre>