title: How to populate a field of a subdocument which is an array element of another document?
body: <pre><code>let collection = await Collection.findOne({ 'works._id': req.params.id }).populate('works.0.photo');
  </code></pre>
  
  <p>This code will populate the <code>work</code> subdoc in index 0, however I want it to populate the index that corresponds to <code>req.params.id</code>.</p>
  
  <p>I want something like <code>.populate('works.i.photo')</code>, where <code>i</code> represents the index of the work which contains an <code>_id</code> that matches <code>req.params.id</code>.</p>
  
  <hr>
  
  <p>I figured out how to do it, but I'm certain there's a better way.</p>
  
  <pre><code>let collection = await Collection.findOne({ 'works._id': req.params.id });
  const idx = collection.works.findIndex(work =&gt; work._id == req.params.id);
  collection = await collection.populate(`works.${idx}.photo`).execPopulate();
  </code></pre>
  
  <p>This doesn't look like the intended way of doing this. Is it possible to do it without iterating to find the index? Preferably with just a single query execution.</p>