title: Return MongoDB docs as a nested object instead of an array using Mongoose
body: <p>The Mongoose <code>find()</code> method returns documents as an array of objects. Is there a &quot;Mongoose&quot; way to return documents as a nested object literal with the document UIDs as the keys? Something similar to what <code>$unwind</code> does after a stage in an aggregate pipeline.</p>
  <p>In other words, how can I do this using <em>just</em> the Mongoose driver, without having to loop over the docs array like in the following example:</p>
  <pre class="lang-js prettyprint-override"><code>docs = Model.find({});
  const nested = {};
  docs.forEach((doc) =&gt; {
      nested[doc._id] = doc;
  });
  </code></pre>
  <p>If this is a duplicate question I apologize, but I could not find the answer to this on here. Maybe I'm not using the correct keywords in my search.</p>