In spring data mongodb using mongotemplate or mongorepository, how to achieve pagination for aggregateion
In addition to ssouris solution you can use Pageable classes for the results.
public Page list(final Pageable pageable) {
final Aggregation agg = newAggregation(
skip(pageable.getPageNumber() * pageable.getPageSize()),
limit(pageable.getPageSize())
);
final List results = mongoTemplate
.aggregate(agg, User.class, UserListItemView.class)
.getMappedResults();
return new PageImpl<>(results, pageable, results.size())
}