Aggregation not working with monger for mongodb version 3.6

423 views Asked by At

Mongo aggregation framework has some changes in version 3.6 Earlier aggregation queries with monger are not working even when we pass :cursor {} as an option. Is there any workaround or do we have to wait for the next monger release?. The error we get is specified below

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" } com.mongodb.connection.ProtocolHelper.getCommandFailureException (ProtocolHelper.java:115)

2

There are 2 answers

0
OSt On

According to mongo db spec, cursor became a required field in some cases. So you should provide it through monger API. It is not a problem in monger, it is a breakable change in mongo db API.

0
sainome-san On

by OSt advice, I could run monger aggregation sample with codes below.

(mc/aggregate db coll
    [{"$project" {:subtotal {"$multiply" ["$quantity", "$price"]}
                  :_id "$state"}}]
    :cursor {:batch-size 0})

thanks!