2016-10-21 2 views
1

스프링 데이터의 mongodb aggregation으로 커서를 리턴하는 방법이 있습니까?Spring 데이터와 함께 커서 Mongo Aggregation

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에서

는 이후 (AFAIK) 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); 
관련 문제