title: Mongoose return 10 results sorted by date for every user id in array of ids
body: <p>lets say we have an array of user ids :</p>
  <pre><code>    &quot;ids&quot;: [
          &quot;623d71c628820d09797be558&quot;,
          &quot;62419d6477775214de099838&quot;,
          &quot;62419d7877775214de099845&quot;,
          &quot;62419d8877775214de09984c&quot;
      ]
  </code></pre>
  <p>and we want to return the first 10 documents of every id sorted by date. I know we can do :</p>
  <pre><code>  const docs = await Model.find({ id: { $in: ids } })
      .sort(&quot;date&quot;)
      .limit(10);
  </code></pre>
  <p>which returns 10 documents sorted by date,but not for every user,how could i return 10 for every one in array ?</p>
  <p>** EDIT **</p>
  <p>Here's an example document from the <code>balance</code> collection:</p>
  <pre class="lang-json prettyprint-override"><code>  {
      &quot;_id&quot;: &quot;624a19a0b1cf7d69a5193737&quot;,
      &quot;user&quot;: {
        &quot;name&quot;: &quot;john&quot;,
        &quot;id&quot;: &quot;623d71c628820d09797be558&quot;
      },
      &quot;description&quot;: &quot;chips&quot;,
      &quot;amount&quot;: 2,
      &quot;type&quot;: &quot;expense&quot;,
      &quot;date&quot;: &quot;2022-04-03T22:03:12.774Z&quot;,
      &quot;__v&quot;: 0
    }
  </code></pre>
  <p>and a &quot;user&quot; document :</p>
  <pre><code>{
          &quot;_id&quot;: &quot;623d71c628820d09797be558&quot;,
          &quot;name&quot;: &quot;john&quot;,
          &quot;__v&quot;: 0
  }
  </code></pre>