Keyset(Seek) Pagination in Spring Data MongoDB

南笙酒味 提交于 2020-12-13 03:57:45

问题


Currently I'm trying to implement keyset, aka. seek pagination for Spring Data MongoDB. Currently I'm trying to go about this by using the information provided here. Unfortunately, this is a low-level implementation, and I was hoping to get some sort of abstraction similar to JOOQ, as they don't seem to support MongoDB.

Is there any abstractions/easy ways out there that would allow me to accomplish this task, or is this something I would need to implement on a low-level on my own?


回答1:


If you are using spring data MongoDb then you could easily achieve it through MongoDB repositories

For example, accessing the second page of User by a page size of 20 you could simply do something like this:

PagingAndSortingRepository repository = // … get access to a bean

Page users = repository.findAll(new PageRequest(1, 20));

For more details, please go through the below official documentation:

  1. https://docs.spring.io/spring-data/data-mongo/docs/1.5.0.RELEASE/reference/html/repositories.html
  2. https://docs.spring.io/spring-data/mongodb/docs/1.3.3.RELEASE/reference/html/mongo.repositories.html
  3. Spring Custom Query with pageable

Hope these documentation solve your problem.



来源:https://stackoverflow.com/questions/59396901/keysetseek-pagination-in-spring-data-mongodb

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!