MongoDB

The Jaspersoft MongoDB Connector

The Jaspersoft MongoDB Connector works with iReport, JasperReports, and JasperReports Server. In previous versions (4.7 and below) the MongoDB driver needed to be installed seprately, you can find instructions on installation for older versions are here: MongoDB Install

Target Audience

Users who want to integrate Jaspersoft's JasperReports Server with MongoDB. This document assumes that the user already has familiarity with MongoDB and already has data in MongoDB collections.

Getting Started

  1. Add a new datasource of type "MongoDB Connection"
  1. Set an appropriate url and test the connection

3. Create a report

The simplest way for a new user to create a new report is with the Report Wizard.

  1. File → New...
  2. Choose any template and click "Launch Report Wizard".
  3. Set the report name and location.
  4. Create a query to retrieve data.
    1. There is no visual query editor, so the button "Design query" is inactive.
    2. The Jaspersoft query language for MongoDB is documented here:

      Jaspersoft MongoDB Query Language

Sample queries

  • Minimal:

    { 'collectionName' : 'accounts' }
  • Specify the fields returned and sort the results:

    {
        'collectionName' : 'accounts',
         'findFields' : {'name':1,'phone_office':1,'billing_address_city':1,'billing_address_street':1,'billing_address_country':1},
         'sort' : {'billing_address_country':-1,'billing_address_city':1}
    }
  • Filtered and parameterized:

    {
         'collectionName' : 'accounts',
         'findQuery' : {
            'status_date' : { '$gte' : $P{StartDate} },
            'name' : { '$regex' : '^N', '$options' : '' }
         }
    }
  • MapReduce job:

    {
      'collectionName' : 'zips',
      'sort' : {
        'value.population' : -1,
      },
      'mapReduce' : {
        'map' : 'function () {
                   emit (this.state, {population : this.pop});
                 }',
        'reduce' : 'function (key, values) {
                      var total = 0;
                      for( var index = 0; index < values.length; index ++) {
                        total += valuesindex.population;
                      }
                      return {population : total}
                   }',
        'out' : 'totalPopulation'
      }
    }

4. Deploy the query executer to JasperReports Server

Import note: These steps are only required if you have JasperReports Server version 4.5.1 or below

  1. Copy the files in WEB-INF from step 1 into /webapps/jasperserver-pro/WEB-INF

  2. Be sure to keep the folder structure when copying the files.
  3. Start or restart JasperReports Server.

5. Deploy the report to JasperReports Server

Create the Data Source

  1. Define the data source in JasperReports Server

    Right-click a folder, add a Data Source

  2. Set the Data Source properties

Create and Run the Report

  1. Use either the JasperReports Server web interface or the iReport Repository Navigator to deploy the report.

    Deploying from iReport is simpler in most cases.

  2. Run the report

    Search for the report or browse to the report in the JasperReports Server repository.

Feedback
randomness