title: SpringData MongoDB pagination not working
body: <p>im here because i don't how to handle this.</p>
  
  <p>I need to paginate the results of a query to a collection in mongodb.</p>
  
  <p>here is my custom query in the repository:</p>
  
  <pre><code>@Query("{'data.consumer': ?0}.skip(?1).limit(?2)")
  List&lt;JSONObject&gt; findAll(String consumer, int size, int page);
  </code></pre>
  
  <p>and here my test method:</p>
  
  <pre><code>@Test
  public void testPaginationResult() {
      List&lt;JSONObject&gt; vehicleCaches;
      for (Integer i = 0; i &lt; 5000; i += 400) {
          vehicleCaches = cacheRepository.findAll("collectionName", i, 400);
          System.out.println(vehicleCaches.size());
      }
  }
  </code></pre>
  
  <p>whene i run the test the output of the system out is always 5000 (the total number of the documents in the collection). 
  It seems like the parameters "size" and "limit" are ignored.</p>
  
  <p>I also tried to use the Class PageRequest, but in that case, the pagination  works ALWAYS in the first iteration, retrieving correctly 400 documents, but after the first iteration, always 0 documents are returns.</p>
  
  <p>here is the code with PageRequest:</p>
  
  <pre><code> for (Integer i = 0; i &lt; total; i += 400) {
  vehicleCaches = cacheRepository.findAll(arguments.get("collection"), PageRequest.of(i, 400));
  </code></pre>
  
  <p>}</p>
  
  <p>I also tried the same code above with with </p>
  
  <pre><code>New PageRequest(i,400);
  </code></pre>
  
  <p>I use </p>
  
  <ul>
  <li>spring data mongodb 2.0.8.RELEASE </li>
  <li>spring 5.0.7.RELEASE </li>
  <li>java 10.0.1</li>
  </ul>