2017-11-24 2 views
5

Ich versuche, eine aggregierte Operation mit Spring Data MongoDB 3.6-rc4 auszuführen.Spring Daten Mongodb - Die 'Cursor' -Option ist erforderlich

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

Aber die folgende Fehlermeldung auf der Abfrage

läuft
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] 

Vielen Dank im Voraus !!

+0

Können Sie ein bisschen mehr Kontext zu machen? Welche MongoDB Version verwendest du? – mp911de

+0

Mongo DB-Version ist v3.6.0-rc4 – rohit

Antwort

4

MongoDB hat in 3.6 geändert, wie der Aggregationsbefehl funktioniert. Aggregationen benötigen jetzt einen Cursor. Wir adapted Spring Data MongoDB 2.1 aber nicht vorherige Versionen.

Aggregationen müssen über die Methode aggregate(…) der Auflistung aufgerufen werden, anstatt den Befehl direkt aufzurufen. Dies ist auch der Grund, warum wir die Änderung nicht rückgängig gemacht haben. executeCommand(…) wird nicht mehr aufgerufen und wir möchten die Kompatibilität in einer Bugfix-Version nicht aufheben.

Der einfachste Ansatz für Sie kann sein, die Methode aggregate(…) zu überschreiben und die entsprechende Methode DBCollection.aggregate(…) mit der zugeordneten Aggregationspipeline aufzurufen.

+0

Ist MongoDB 3.4 kompatibel mit der aktuellen Version von Federdaten und unterstützt Aggregate? – rohit

+0

Ja, es wird vollständig unterstützt. – mp911de

+0

Hallo Leute. Kürzlich mit dem gleichen Problem konfrontiert. Soweit ich das verstehe, sollte ich einen der folgenden Schritte ausführen: a) Ich warte auf die Veröffentlichung von Spring Data MongoDB 2.1, b) erstelle meine eigene Klasse von MongoTemplate und überschreibe die aggregate() Methode, indem ich alle Änderungen in PR https: // einfüge. github.com/spring-projects/spring-data-mongodb/pull/515. Bin ich richtig? –

1

Ich habe auch diese Art von Fehler konfrontiert, wenn Sie Mongodb Version 3.6.2 verwenden.

Überprüfen Sie Ihre Version von org.springframework.data in pom.xml

Für mich, ich habe org.springframework.data Version geändert 2.0.3.RELEASE und mein Problem wurde gelöst .

0

Ich war mit:

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

Dann nach meiner Abhängigkeit auf eine höhere Version aktualisiert haben, wurde das Problem behoben:

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