title: How to replace collection in query result Mongo
body: <p>I queried to get info from a table with a manytomany relationship like this</p>
  <pre><code>$userList = UserListing::where('user_id', $user-&gt;id)-&gt;with(&quot;objects&quot;)-&gt;paginate(10);
  </code></pre>
  <p>Now, i want to limit the amount of results in the &quot;Objects&quot; table, but at the same time i want to know how many objects are in total.</p>
  <pre><code>        $userList = UserListing::where('user_id', $user-&gt;id)-&gt;with([&quot;objects&quot;=&gt; function($query) {
               $query-&gt;take(2);
          }])-&gt;paginate(10);
  </code></pre>
  <p>But by doing this, i can't get the total of objects since i limited it to 2, then i tried to process the info like this</p>
  <pre><code>$userList = UserListing::where('user_id', $user-&gt;id)-&gt;with(&quot;objects&quot;)-&gt;paginate(10);
  
  foreach ($userList as $key =&gt; $value) {
      $l = count($value[&quot;objects&quot;]);
      $value[&quot;objects&quot;] = $value[&quot;objects&quot;]-&gt;take(2);
      $value[&quot;number_objects&quot;] = $l;
  }
  </code></pre>
  <p>But apparently this did not replace the collection value[&quot;objects&quot;], since it still returned 3 objects, despite supposedly being reduced with <code>$value[&quot;objects&quot;] = $value[&quot;objects&quot;]-&gt;take(2);</code>. How can i replace the collection with the reduced one?</p>