title: Indexing Array Items In Mongoose
body: <p>I have a schema that looks something like ...</p>
  
  <pre class="lang-js prettyprint-override"><code>const itemSchema = new Schema({
      sizes: [{
          type: String,
          enum: [/* some fixed sizes */],
      }],
      // other properties ...
  });
  </code></pre>
  
  <p>I perform queries of the form <code>Items.find({ sizes: { $elemMatch: 'someSize' } });</code><br>
  So I want to add index to those sizes inside of an element so the query is performed quickly.</p>
  
  <p>Should it be something like:</p>
  
  <pre class="lang-js prettyprint-override"><code>const itemSchema = new Schema({
      sizes: [{
          type: String,
          enum: [/* some fixed sizes */],
          index: true,
      }],
      // other properties ...
  });
  </code></pre>
  
  <p>or</p>
  
  <pre class="lang-js prettyprint-override"><code>const itemSchema = new Schema({
      sizes: {
          type: [{
              type: String,
              enum: [/* some fixed sizes */],
          }],
          index: true,
      },
      // other properties ...
  });
  </code></pre>
  
  <p>or maybe a third option ?</p>