This is my current pagination method on Spring Data MongoDB:
@RequestMapping(value="/nextposts", method=RequestMethod.GET)
public List getNextPosts(@RequestParam int next) {
Pageable pageable = new PageRequest(next, 5, new Sort(new Sort.Order(Direction.DESC, "id")));
page = repo.findAll(pageable);
return page.getContent();
}
As you can see, I'm obtaining the page as specified by the "next" variable and then returning it to the user.
I'm trying to get a handle on the last document returned in the page, specifically to get its ObjectId so I can implement "Approach 2" of fast pagination with mongodb: http://blog.mongodirector.com/fast-paging-with-mongodb/
I have looked on the docs for PageRequest and Pageable but none of the methods will return the last document in the page.
PageRequest: http://docs.spring.io/spring-data/data-commons/docs/current/api/org/springframework/data/domain/PageRequest.html
Does anyone know how this can be done?
Eventually I couldn't do it with the MongoRepository.
I had to use the MongoOperation / MongoTemplate to do this task.