MongoDB Data Sources

MongoDB is a big data architecture based on the NoSQL model that is neither relational nor SQL-based. We provide a connector that allows reports to use MongoDB as a data source. Reports based on a MongoDB data source can be used as Topics that allow users to create Ad Hoc views based on the fields returned by the MongoDB query.

As with all big data stores, MongoDB data sources have the following limitations and usage guidelines within JasperReports Server:

MongoDB data sources are not supported for OLAP connections
MongoDB data sources cannot be used directly in Domains. To use MongoDB in a Domain, see Big Data Connectors for Virtual Data Sources.
MongoDB data sources can be used in Ad Hoc Topics, but they do not support query optimization.
You must configure your query limits to handle big data (see Ad Hoc Data Policies for Big Data).
You must configure your JVM memory to handle the expected amount of data (see the JasperReports Server Installation Guide).

To create a MongoDB data source:

1. Log on as an administrator.
2. Click View > Repository, expand the folder tree, and right-click a folder to select Add Resource > Data Source from the context menu. Alternatively, you can select Create > Data Source from the main menu on any page and specify a folder location later. If you have installed the sample data, the suggested folder is Data Sources. The New Data Source page appears.
3. In the Type field, select MongoDB Data Source. The information on the page changes to reflect what’s needed to define a MongoDB data source.

You have the option to use profile attributes to derive the values for data source parameters. See Attributes in Data Source Definitions

MongoDB Data Source Page

4. Fill in the required fields, along with any optional information.

The MongoDB URI has the form: mongodb://<hostname>:27017/<database>

5. The schema is used only if you plan to wrap the MongoDB data source in a virtual data source for use in a Domain. For instructions, see Relational Schema for MongoDB Connector.
6. Click Test Connection to validate the data source.
7. When the test is successful, click Save. The Save dialog appears.

Saving the MongoDB Connection

8. Enter the data source name and, optionally, a description. the Resource ID appears based on the name you enter.
9. Expand the folder tree and select the location for your data source, then click Save. The data source appears in the repository.

MongoDB is designed to be accessed through API calls in an application or a command shell. As a consequence, it does not have a defined query language. In order to write queries for MongoDB data sources, we have developed a query language based on the JSON-like objects upon which MongoDB operates. JSON is the JavaScript Object Notation, a textual representation of data structures that is both human- and machine-readable.

The Jaspersoft MongoDB Query Language is a declarative language for specifying what data to retrieve from MongoDB. The connector converts this query into the appropriate API calls and uses the MongoDB Java connector to query the MongoDB instance. The following examples give an overview of the Jaspersoft MongoDB Query Language, with SQL-equivalent terms in parentheses:

Retrieve all documents (rows) in the given collection (table):
{ 'collectionName' : 'accounts' }
From all documents in the given collection, select the named fields (columns) and sort the results:
  'collectionName' : 'accounts',
  'findFields' : {'name':1,'phone_office':1,'billing_address_city':1,
  'sort' : {'billing_address_country':-1,'billing_address_city':1}
Retrieve only the documents (rows) in the given collection (table) that match the query (where clause). In this case, the date is greater-than-or-equal to the input parameter, and the name matches a string (starts with N):
  'collectionName' : 'accounts',
  'findQuery' : {
    'status_date' : { '$gte' : $P{StartDate} },
    'name' : { '$regex' : '^N', '$options' : '' }

The Jaspersoft MongoDB Query Language also supports advanced features of MongoDB such as map-reduce functions and aggregation that are beyond the scope of this document. For more information, see the language reference on the Community website.