As you found out, MongoTemplate does not support full page abstraction. Like KneeLess, you can use @Query-Annotation to do some custom queries.
In case this is not enough, you can use the Spring Repository PageableExecutionUtilsin combination with your MongoTemplate.
For example, for example:
@Override
public Page<XXX> findSophisticatedXXX( @NotNull Pageable pageable) {
Query query = query(
where("...")
).with(pageable);
List<XXX> list = mongoOperations.find(query, XXX.class);
return PageableExecutionUtils.getPage(list, pageable,
() -> mongoOperations.count(query, XXX.class));
}
Spring Repositories do the same. As you can see here , they also run two queries.
d0x source
share