In spring data mongodb how to achieve pagination for aggregation

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

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

7条回答
  •  青春惊慌失措
    2021-02-06 00:23

    You can use MongoTemplate

    org.spring.framework.data.mongodb.core.aggregation.Aggregation#skip
            and 
    org.springframework.data.mongodb.core.aggregation.Aggregation#limit
    
    Aggregation agg = newAggregation(
            project("tags"),
            skip(10),
            limit(10)
    );
    
    AggregationResults results = mongoTemplate.aggregate(agg, "tags", TagCount.class);
    List tagCount = results.getMappedResults();
    

提交回复
热议问题