gpt4 book ai didi

mongodb - 带有 Spring Data Mongo 聚合的游标

转载 作者:可可西里 更新时间:2023-11-01 09:58:48 28 4
gpt4 key购买 nike

有没有办法通过 spring data 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());

最佳答案

Solution在这里引用:

从 spring-data-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);

关于mongodb - 带有 Spring Data Mongo 聚合的游标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40180270/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com