복붙노트

[SPRING] 스프링 데이터 mongodb - '커서'옵션이 필요합니다.

SPRING

스프링 데이터 mongodb - '커서'옵션이 필요합니다.

스프링 데이터 MongoDB 3.6-rc4를 사용하여 집계 연산을 실행하려고합니다.

Aggregation agg = newAggregation(
    lookup("orders", "orderId", "_id", "order") 
);
List<BasicDBObject> results = mongoOperations.aggregate(agg, "transactions", BasicDBObject.class).getMappedResults();

그러나 쿼리 실행시 다음 오류가 발생합니다.

2017-11-24 17:03:41,539 WARN  org.springframework.data.mongodb.core.MongoTemplate : Command execution of { "aggregate" : "transactions" , "pipeline" : [ { "$lookup" : { "from" : "orders" , "localField" : "orderId" , "foreignField" : "_id" , "as" : "order"}}]} failed: The 'cursor' option is required, except for aggregate with the explain argument
2017-11-24 17:03:41,574 ERROR org.apache.catalina.core.ContainerBase.[Tomcat].[localhost].[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.dao.InvalidDataAccessApiUsageException: Command execution failed:  Error [The 'cursor' option is required, except for aggregate with the explain argument], Command = { "aggregate" : "transactions" , "pipeline" : [ { "$lookup" : { "from" : "orders" , "localField" : "orderId" , "foreignField" : "_id" , "as" : "order"}}]}; nested exception is com.mongodb.MongoCommandException: Command failed with error 9: 'The 'cursor' option is required, except for aggregate with the explain argument' on server localhost:27017. The full response is { "ok" : 0.0, "errmsg" : "The 'cursor' option is required, except for aggregate with the explain argument", "code" : 9, "codeName" : "FailedToParse" }] with root cause
com.mongodb.MongoCommandException: Command failed with error 9: 'The 'cursor' option is required, except for aggregate with the explain argument' on server localhost:27017. The full response is { "ok" : 0.0, "errmsg" : "The 'cursor' option is required, except for aggregate with the explain argument", "code" : 9, "codeName" : "FailedToParse" }
    at com.mongodb.CommandResult.getException(CommandResult.java:80) ~[mongo-java-driver-3.5.0.jar:na]
    at com.mongodb.CommandResult.throwOnError(CommandResult.java:94) ~[mongo-java-driver-3.5.0.jar:na]
    at org.springframework.data.mongodb.core.MongoTemplate.handleCommandError(MongoTemplate.java:2100) ~[spring-data-mongodb-1.10.8.RELEASE.jar:na]
    at org.springframework.data.mongodb.core.MongoTemplate.aggregate(MongoTemplate.java:1577) ~[spring-data-mongodb-1.10.8.RELEASE.jar:na]
    at org.springframework.data.mongodb.core.MongoTemplate.aggregate(MongoTemplate.java:1505) ~[spring-data-mongodb-1.10.8.RELEASE.jar:na]

미리 감사드립니다 !!

해결법

  1. ==============================

    1.MongoDB는 3.6에서 집계 명령의 작동 방식을 변경했습니다. 집계에는 이제 커서가 필요합니다. 우리는 스프링 데이터 MongoDB 2.1을 채택했지만 이전 버전은 적용하지 않았습니다.

    MongoDB는 3.6에서 집계 명령의 작동 방식을 변경했습니다. 집계에는 이제 커서가 필요합니다. 우리는 스프링 데이터 MongoDB 2.1을 채택했지만 이전 버전은 적용하지 않았습니다.

    집계는 명령을 직접 호출하는 대신 콜렉션의 집계 (...) 메소드를 통해 호출해야합니다. 이것이 변경 사항을 백 포트하지 않은 이유이기도합니다. executeCommand (...)는 더 이상 호출되지 않으며 bugfix 릴리스에서 호환성을 해제하고 싶지 않습니다.

    가장 쉬운 방법은 집계 (...) 메서드를 재정의하고 매핑 된 집계 파이프 라인을 사용하여 DBCollection.aggregate (...) 적절한 메서드를 호출하는 것입니다.

  2. ==============================

    2.내가 사용했던 :

    내가 사용했던 :

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.8.RELEASE</version>
        <relativePath></relativePath>
    </parent>
    

    그런 다음 상위 버전으로의 종속성을 업그레이드 한 후에 문제가 해결되었습니다.

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.10.RELEASE</version>
        <relativePath></relativePath>
    </parent>
    
  3. ==============================

    3.@ mp911de에 의해 언급 된 Pull Request는 Spring Data MongoDB의 1.10.10 버전에서 릴리스되었습니다. 그래서 당신은

    @ mp911de에 의해 언급 된 Pull Request는 Spring Data MongoDB의 1.10.10 버전에서 릴리스되었습니다. 그래서 당신은

  4. ==============================

    4.또한 Mongodb 버전 3.6.2를 사용할 때 이런 유형의 오류가 발생했습니다.

    또한 Mongodb 버전 3.6.2를 사용할 때 이런 유형의 오류가 발생했습니다.

    pom.xml의 org.springframework.data 버전을 확인하십시오.

    나를 위해, 나는 org.springframework.data 버전을 2.0.3.RELEASE로 바꾸었고 나의 문제가 해결되었다.

  5. ==============================

    5.

    Just updating the spring boot version works for me.
    This is the version that I have used and worked....
    <parent>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-parent</artifactId>
            <version>1.5.10.RELEASE</version>
        </parent>
    
  6. ==============================

    6.또한 org.springframework.data 버전 1.10.3.RELEASE를 사용할 때 이런 유형의 오류가 발생했습니다. 그리고 버전을 2.0.5로 변경했습니다. 릴리스와 내 문제가 해결되었습니다.

    또한 org.springframework.data 버전 1.10.3.RELEASE를 사용할 때 이런 유형의 오류가 발생했습니다. 그리고 버전을 2.0.5로 변경했습니다. 릴리스와 내 문제가 해결되었습니다.

  7. ==============================

    7.집계 쿼리 파이프 라인에서 사용할 수있는 커서 옵션을 사용할 수 있습니다.

    집계 쿼리 파이프 라인에서 사용할 수있는 커서 옵션을 사용할 수 있습니다.

    {cursor: { batchSize: batch_size }}
    

    https://docs.mongodb.com/manual/reference/method/db.collection.aggregate/

    이 경우 Aggregation.newAggregation (AggregationOperation ... operations) .withOptions (새 AggregationOptions (false, false, 새 Document (). append ( "batchSize", batch_size)))가 도움이 될 수 있습니다.

  8. from https://stackoverflow.com/questions/47472688/spring-data-mongodb-the-cursor-option-is-required by cc-by-sa and MIT license