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".
Here is the code sample:
do {
Pageable pageable = new PageRequest(pageNumber, PAGE_SIZE, sort);
nextPage = catsRepository.findByTypeAndIdGreaterThan("street cat", lastId,
pageable);
dbRecords = nextPage.getContent();
if (dbRecords.size() > 0) {
lastId = new ObjectId( doSomthing());
pageNumber++;
}
} while (nextPage.hasNext());
Also, when using different page size, it seems like the location of the problem is different:
After running with slice of size 1, problem at slice 133
After running with slice of size 2, problem at slice 98
After running with slice of size 3, problem at slice 76
Is there a malformed document in the DB that can cause this?
During the iteration I calculate the expected number of slices / pages and the loops stops before it reaches that number.
what can cause such a thing?
Thanks.