3 November 2011

Filtering on multiple fields in MongoDB

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

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

Like this:

Related

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.

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.