MongoDB City Cases Example


This is an example report developed using Jaspersoft Studio and then published to JasperReports Server. All the data comes from a single MongoDB collection called "cases". 

Features of the reports are:

  • Aggregation framework
  • Geospacial features of MongoDB including the $geoNear operator
  • Parametrized queries, including the $in operator passed to a collection
  • JasperReports Map component
  • Drill through from map
  • Sub-reports


  • JasperReports Server v5.5 Professional or Enterprise (I used HTML5 charts, otherwise this would work in CE)
  • MongoDB >2.4 (I use geospatial features not available in older versions)

Getting the Data

For those wanting to generate the data themselves:

The data was generated randomly using - you are welcome to recreate the data yourself using this as a template. You can save the generated JSON to a file and then run these commands:

Import the raw json file to mongodb:

mongoimport -c cases --jsonArray --drop --file ~/Desktop/json_file.json

Cast the dates to ISO dates:

mongo --eval "db.cases.find().forEach(function(doc){doc.CaseOpenDatetime = new Date(doc.CaseOpenDatetime);});"
mongo --eval "db.cases.find().forEach(function(doc){doc.CaseBeginDatetime = new Date(doc.CaseBeginDatetime);});"
mongo --eval "db.cases.find().forEach(function(doc){doc.CaseCurrentStatusDatetime = new Date(doc.CaseCurrentStatusDatetime);});"

Add a Geospatial index for the lat/longitude :

mongo --eval " db.cases.ensureIndex({"location" : "2dsphere" } );”

For those wanting to get started quickly:

You can simply download the collection here - you will then need to import it

Import data :

mongoimport --host localhost --db test --collection cases < mongodb_cases.json

Add a Geospatial index for the lat/longitude :

mongo --eval " db.cases.ensureIndex({"location" : "2dsphere" } );”

Getting the Reports

You should be running JasperReports Server v5.5 for this to work - it likely works in previous versions but not guaranteed. You will simply need to log in as superuser and import this repository export.

The import should bring in a folder under /public/ called MongoDB. It will also import a Topic that you can use in Ad-Hoc, that topic will alse be under the Public Topics folder.


The main report in action:

Page 2 of the drill through report showing off the $near operator of MongoDB:

Data Exploration

This section was contributed by emistry

This data was used to setup Adhoc Data Exploration from JasperReports Server using a Domain . The schema used when setting up the data source was :

CaseCurrentStatus VARCHAR(255),
ServiceName VARCHAR(255),
CaseLat FLOAT,
CaseLong FLOAT,
gender VARCHAR(255),

A link to a short video to explain the whole process of setting up Adhoc Data Exploration is found