2017-11-24 6 views
5

SpringデータMongoDB 3.6-rc4を使用して集約演算を実行しようとしています。Springデータmongodb - 'cursor'オプションが必要です

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] 

感謝を実行する上で、次のエラーを取得します!

+0

をあなたはもう少しコンテキストを提供することができますか?どのMongoDBのバージョンを使用していますか? – mp911de

+0

Mongo DBバージョンはv3.6.0-rc4 – rohit

答えて

4

MongoDBが3.6で変更されました。集計には現在カーソルが必要です。我々はadapted Spring Data MongoDB 2.1ですが、以前のバージョンはありません。

集計は、コマンドを直接呼び出す代わりに、コレクションのaggregate(…)メソッドを使用して呼び出す必要があります。これが私たちが変更をバックポートしなかった理由です。 executeCommand(…)は呼び出されなくなりました。バグ修正リリースでは互換性を失いたくありません。

最も簡単な方法は、aggregate(…)メソッドをオーバーライドし、適切なメソッドDBCollection.aggregate(…)をマップされた集約パイプラインで呼び出すことです。

+0

MongoDB 3.4は現在のバージョンのスプリングデータと互換性があり、集約をサポートしていますか? – rohit

+0

はい、完全にサポートされています。 – mp911de

+0

こんにちは。最近、同じ問題に直面した。これまでのところ、私は次のいずれかを行うべきだと理解しています:a)Spring Data MongoDB 2.1のリリースを待つこと、(b)MongoTemplateから継承した自分のクラスを作成し、PR https://に含まれるすべての変更を導入してaggregate() github.com/spring-projects/spring-data-mongodb/pull/515。 私はそうですか? –

1

また、Mongodbバージョン3.6.2を使用しているときにこのタイプのエラーが発生しました。

私にとってのpom.xml

org.springframework.dataのバージョンを確認し、私は2.0.3.RELEASEするorg.springframework.dataバージョンを変更しているし、私の問題が解決しました。私が使っていた

0

:後の上位バージョンへの私の依存関係をアップグレード

<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> 
関連する問題