Right Outer Join

3 November 2011

Filtering on multiple fields in MongoDB

Filed under: JasperReports — Tags: , — mdahlman @ 23:07

Filtering on multiple fields in MongoDB

This thread got me thinking about filtering on multiple fields in a MongoDB query. The author of the original question attempted to use the $and operator which was introduced in MongoDB 2.0. But that’s not needed for simple queries that filter on multiple fields. I created a simple report to show the idea.

Filtering on multiple fields at once in MongoDB

Filtering on multiple fields at once in MongoDB

The report is available here if you want to play with it. Here’s the sample data I used:

db.shiraz.save( { "ServiceType" : "sms", "ServiceHealthState" : "ok", "DocumentID" : "11" } )
db.shiraz.save( { "ServiceType" : "sms", "ServiceHealthState" : "ok", "DocumentID" : "12" } )
db.shiraz.save( { "ServiceType" : "sms", "ServiceHealthState" : "ko", "DocumentID" : "13" } )
db.shiraz.save( { "ServiceType" : "jms", "ServiceHealthState" : "critical", "DocumentID" : "21" } )
db.shiraz.save( { "ServiceType" : "jms", "ServiceHealthState" : "critical", "DocumentID" : "22" } )

If you haven’t used (or heard of!) the Jaspersoft connector for MongoDB, then start with this article.

Advertisements

3 Comments »

  1. Thank you for posting these examples! The MongoDB_Multifield_Filter.jrxml compiles and previews without error in ireports designer 4.5.0. When I deploy the report to jasperserver I am getting this error:
    java.lang.Exception: 1 – net.sf.jasperreports.engine.JRException: No MongoDB connection      at com.jaspersoft.ireport.jasperserver.ws.WSClient.runReport(WSClient.java:403)      at com.jaspersoft.ireport.jasperserver.ws.WSClient.runReporot(WSClient.java:320)      at com.jaspersoft.ireport.jasperserver.ReportRunner.run(ReportRunner.java:70)      at org.openide.util.RequestProcessor$Task.run(RequestProcessor.java:572)      at org.openide.util.RequestProcessor$Processor.run(RequestProcessor.java:997) 

    Is there anything additional I need to modify\include to deploy reports with subDatasets (embedded queries, i.e. not sub reports)?
    *note* I can deploy\run reports without subDatasets.. but I would really like to get my reports with table and list components (which run in report designer) to run on the server.

    Any help would be appreciated. Thank you.

    Comment by Renea — 23 May 2012 @ 07:37

    • Renea, excellent question!
      It’s a bug that it’s possible to create a report which works in iReport but fails in JasperReports Server (JRS). It has been fixed in later versions of the connector. These will be available soon.

      For now your workaround is simple (but not obvious). When you define the List or Table component, you probably define the “Connection Datasource/exp” as $P{REPORT_CONNECTION}. This is correct… but it wasn’t sufficient for JRS. Keep that value, but also go to the tab “Parameters map exp” and set it to $P{REPORT_PARAMETERS_MAP}.

      In effect, this passes the connection info twice. Once in a way iReport uses and once in a way JRS uses. In the next release of the connector, $P{REPORT_CONNECTION} will be enough for both iReport and JRS.

      Comment by mdahlman — 23 May 2012 @ 09:19

      • Matt, this works perfectly! Thank you for your fast response.
        This has literally saved me hours of anguish 🙂

        Comment by Renea — 23 May 2012 @ 10:34


RSS feed for comments on this post. TrackBack URI

Go on... leave a reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: