Aggregate method in jongo!!!

175 views
Skip to first unread message

Raees Khan

unread,
Jul 16, 2018, 10:02:55 AM7/16/18
to Jongo
Hello,

Do jongo supports mongodb 3.6 features? I have an issue. I installed ubuntu 18.04 and mongodb 3.6. First I tried to install mongodb 3.4 but not succeeded. 
Now the following code throws error:

Iterable<Script> output = script().aggregate("{$match:{_id:#}}", id).and("{$project:{" +
" \"params\": {$filter: {" +
" input: '$params'," +
" as: 'params'," +
" cond: {$eq: ['$$params.id', #]}" +
" }}" +
" }}", paramId).and().as(Script.class);
return output;

 The error is the following: 
 Execution exception[[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" }]]

How to add "explain" or "cursor" in the above code? or how to downgrade mongodb to 3.4 in ubuntu 18? Or any suggestion is welcome.

Thank you.
Raees

Anirudh Simha

unread,
Jul 23, 2018, 6:01:30 AM7/23/18
to Jongo
Use MongoClient AggregationOptions OutputMode and use it in the aggregation as follows:

AggregationOptions options = AggregationOptions.builder().outputMode(OutputMode.CURSOR).build();
Iterable<Script> output = script().aggregate("{$match:{_id:#}}", id).and("{$project:{" +
" \"params\": {$filter: {" +
" input: '$params'," +
" as: 'params'," +
" cond: {$eq: ['$$params.id', #]}" +
" }}" +
        "    }}", paramId).and().options(options).as(Script.class);
return output;

Raees Khan

unread,
Jul 23, 2018, 12:03:49 PM7/23/18
to jongo...@googlegroups.com
Hello,

Thank you very much it works for me with your code.

--
You received this message because you are subscribed to the Google Groups "Jongo" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jongo-user+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages