2016-10-21 10 views
1

春データのmongodb集約でカーソルを返す方法はありますか?春データのカーソルMongo集計

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

答えて

1

mongodbのスプリングデータは、集約時にカーソルの使用をサポートしていません。 MongoDB Javaドライバを代わりに使用する必要があります。ここに引用

+0

残念ながらサポートされていません。これはJIRAの問題です:[DATAMONGO-939](https://jira.spring.io/browse/DATAMONGO-939) – MirceaG

2

Solution

を春・データ・モンゴバージョン以降2.0.0.M4(私の知る限り)からMongoTemplateはaggregateStream方法を得ました。

ですから、次の操作を行うことができます。

AggregationOptions aggregationOptionsの=のAggregation.newAggregationOptions() //これは非常に重要です:あなたはバッチサイズを設定しない場合、あなたは一度とで、すべてのオブジェクトを取得します戻りデータセットが大きすぎる場合、メモリが不足する可能性があります。 .cursorBatchSize(mongoCursorBatchSize) .build();

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