Jump to content

Jaspersoft MongoDB Query Language: Aggregation and projection

Go to solution Solved by kkumlien,

Recommended Posts


I have a Mongo Query which is extracting the subducument from a collection and projects its fields.

The query is working fine, but I am not able to put it into the Jaspersoft MongoDB Query which is necessary for getting the dataset!

I looked through https://community.jaspersoft.com/wiki/jaspersoft-mongodb-query-language

but without success.

Is anybody able to convert this statement into a working query for a jasper report?


    $unwind: "$b"
}, {
    $project: {
        attribute: "$b.attribute"


Any help would be highly appreciated!


Link to comment
Share on other sites

  • Replies 17
  • Created
  • Last Reply

Top Posters In This Topic

  • 3 weeks later...

I also getting this error since upgrading to MongoDB 3.6.3. It only occurs when doing an aggregation query.

2018-03-05 10:15:32,130 ERROR GenericExceptionMapper,http-nio-8080-exec-3:50 - Unexpected error occurs
net.sf.jasperreports.engine.JRException: The 'cursor' option is required, except for aggregate with the explain argument
    at com.jaspersoft.mongodb.query.MongoDbQueryWrapper.runCommand(MongoDbQueryWrapper.java:207)
    at com.jaspersoft.mongodb.query.MongoDbQueryWrapper.processQuery(MongoDbQueryWrapper.java:115)
    at com.jaspersoft.mongodb.query.MongoDbQueryWrapper.<init>(MongoDbQueryWrapper.java:93)
    at com.jaspersoft.mongodb.query.MongoDbQueryExecuter.createDatasource(MongoDbQueryExecuter.java:104)

When specifying the options field using the  jaspersoft-mongodb-query-language, i get the following error in the log:

2018-03-05 10:14:12,893 ERROR JRQueryExecuterAdapter,http-nio-8080-exec-7:155 - Error while executing query
net.sf.jasperreports.engine.JRException: unrecognized field 'options'

I've replaced the java driver in the server lib dir but the error persists.


Link to comment
Share on other sites

  • 2 months later...

There was a change in MongoDB version 3.6. Per MongoDB docs (https://docs.mongodb.com/manual/reference/command/aggregate/#dbcmd.aggregate):

Changed in version 3.6: MongoDB 3.6 removes the use of aggregate command without the cursor option unless the command includes the explain option. Unless you include the explain option, you must specify the cursor option.

So, you just need to add an empty "cursor" document.

Also, pipeline needs to be an array.

So, your query in JR needs to be similar to the following example:

{    "runCommand": {        "aggregate" : "{collection name}",        "pipeline" : [            {                "$match": {                    ...                }            },            {                ...            }        ],        "cursor": {}    }}[/code]


Link to comment
Share on other sites

  • 1 month later...

It doesn't work even if the empty cursor block is given.

The issue is that the Jaspersoft mongodb Connector (js-mongodb-datasource-2.0.9.jar) - the code is expecting the result data as inline results ('results' field). But MongoDB 3.6 results a cursor.
So it gives a 'No results exception' . This requires code change in the js-mongodb-datasource-2.0.9.jar and needs to be rebuilt. I could n't find the source of this component any where.

Due to this issue, Jasper report is almost unusable in all typical reports with MongoDB 3.6 and 4.0

Please help to resolve this issue

Link to comment
Share on other sites

  • 3 weeks later...
  • 11 months later...
  • 4 weeks later...
  • 4 weeks later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...