title: Page / Slice containing unknown instances in spring's pagination and slicing over mongodb
body: <p>When trying to use spring's pagination or slicing to iterate a very large mongodb collection, the program runs ok but at certain point the next page / slice is empty and in debug there is the message of "Page / Slice containing unknown instances".</p>
  
  <p>Here is the code sample:</p>
  
  <pre><code>do {
    Pageable pageable = new PageRequest(pageNumber, PAGE_SIZE, sort);
    nextPage = catsRepository.findByTypeAndIdGreaterThan("street cat", lastId, 
            pageable);
    dbRecords = nextPage.getContent();
     if (dbRecords.size() &gt; 0) {
         lastId = new ObjectId( doSomthing());
         pageNumber++; 
  
      }
   } while (nextPage.hasNext());
  </code></pre>
  
  <p>Also, when using different page size, it seems like the location of the problem is different:</p>
  
  <p>After running with slice of size 1, problem at slice 133</p>
  
  <p>After running with slice of size 2, problem at slice  98</p>
  
  <p>After running with slice of size 3, problem at slice 76</p>
  
  <p>Is there a malformed document in the DB that can cause this?</p>
  
  <p>During the iteration I calculate the expected number of slices / pages and the loops stops before it reaches that number.</p>
  
  <p>what can cause such a thing?</p>
  
  <p>Thanks.</p>