In spring data mongodb how to achieve pagination for aggregation

前端 未结 7 1521
渐次进展
渐次进展 2021-02-05 23:32

In spring data mongodb using mongotemplate or mongorepository, how to achieve pagination for aggregateion

7条回答
  •  名媛妹妹
    2021-02-06 00:21

    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())
    }
    

提交回复
热议问题