Mongodb 带有Spring数据Mongo聚合的游标

Mongodb 带有Spring数据Mongo聚合的游标,mongodb,aggregation-framework,Mongodb,Aggregation Framework,有没有方法返回带有spring数据mongodb聚合的游标 Aggregation agg = newAggregation( match(Criteria.where("_id").is(objId)), unwind("taskResultContent"), project("taskResultContent.executionUUID","taskResultContent.returnContent","task

有没有方法返回带有spring数据mongodb聚合的游标

Aggregation agg = newAggregation(
            match(Criteria.where("_id").is(objId)),
            unwind("taskResultContent"),
            project("taskResultContent.executionUUID","taskResultContent.returnContent","taskResultContent.sequency").and("resultID").previousOperation(),
            match(Criteria.where("executionUUID").is(executionUUID)),
            sort(DESC,"sequency")
        ).withOptions(Aggregation.newOptions().cursor(cursor).build());

Spring data for mongodb不支持在聚合时使用游标。必须改用MongoDB java驱动程序。

在此引述:

从spring数据mongo版本2.0.0.M4开始(AFAIK),MongoTemplate获得了aggregateStream方法

因此,您可以执行以下操作:

 AggregationOptions aggregationOptions = Aggregation.newAggregationOptions()
    // this is very important: if you do not set the batch size, 
    // you'll get all the objects at once and you might run out of memory
    // if the returning data set is too large
    .cursorBatchSize(mongoCursorBatchSize)
    .build();

data = mongoTemplate.aggregateStream(Aggregation.newAggregation(
       Aggregation.group("person_id")
                  .count()
                  .as("count"))
                  .withOptions(aggregationOptions), collectionName, YourClazz.class);

不幸的是,我们不支持。这就是JIRA问题: