Created
September 23, 2025 14:31
-
-
Save adrianojlt/8ea3986a6ada98073e7b5fb5ad71633e to your computer and use it in GitHub Desktop.
mongoTemplate with pagination
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Pageable pageable = PageRequest.of(0, 10); | |
| // Build query without pagination first | |
| Query query = new Query(); | |
| // Add criteria's here | |
| long total = mongoTemplate.count(query, Patient.class); | |
| query.with(pageable); // Apply pagination only for the find operation | |
| List<Patient> filteredPatients = mongoTemplate.find(query, Patient.class, "patient"); | |
| Page<Patient> patientPage = new PageImpl<>(filteredPatients, pageable, total); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment