Connecting to MongoDB using Reporting Wizard

In this recipe, we will guide you through the steps required to simply get data in the quickest fashion from MongoDB using a feature of the Pentaho Report Designer called the Report Designer Wizard. This wizard helps us to define our connection to the MongoDB data source, as well as to define a query that is to be executed to get data into our report.

Getting ready

To get ready for this recipe, you first need to start the MongoDB server with the same database as in the last chapter. You will also want to start the Pentaho Report Designer.

The Pentaho Report Designer is started in Windows as follows:

This can be done via the Windows Start menu by navigating to Start | All Programs | Pentaho Enterprise Edition | Design Tools | Report Designer and then by clicking on the report designer icon.

The Pentaho Report Designer is started in Linux as follows:

Open up a terminal and navigate to the PentahoEE/design-tools/report-designer folder. Execute the report-designer bash script using ./report-designer.sh.

When the Report Designer loads, you should be presented with a Welcome screen.

How to do it…

In this section, we are going to create a simple report using the Pentaho Report Design Wizard and the data from MongoDB:

  1. Click on the Report Wizard button on the Pentaho Report splash screen:
    How to do it…
  2. Select Cobalt Template and click on Next:
    How to do it…
  3. Add a new data source by clicking on the plus icon in the top-right corner of the window:
    How to do it…
  4. Select MongoDB from the pop-up list of data sources.
  5. Add a new query by clicking on the plus icon in the top-left corner of the window.
  6. Give the Query a name like Orders.
  7. Set the Host property to localhost.
  8. Set the Port property to 27017.
  9. By default, you do not need to specify a username or password for a default MongoDB installation:
    How to do it…
  10. Select the Input Options tab.
  11. Click on the Get DBs button to return a list of available Databases in the MongoDB connections.
  12. Select the SteelWheels Databases.
  13. Click on the Get Collections button to return a list of available MongoDB collections in the databases.
  14. Select the Orders collections from the list:
    How to do it…
  15. Click on the Query tab.
  16. Copy and paste the following query into the Query Expression (JSON) text area:
    {
      $query: {},
      $orderby: {
        customer.address.country:1,
        customer.address.city:1,
        product.line:1,
      }
    }
  17. Copy and paste the following filter into the Fields Expression (JSON) input:
    {
      customer.address.country:1,
      customer.address.city:1,
      product.line:1,
      totalPrice:1
    }
    How to do it…
  18. Click on the Fields tab.
  19. Click on the Get fields button, as shown in the following screenshot:
    How to do it…
  20. Click on Preview. You should see five fields of data ordered by country, city, and then product line:
    How to do it…
  21. Click on OK to exit the Query Wizard.

Now that the query has been defined, you should return to the main Report Wizard window with your query available to be selected.

  1. Select your query from the Data Source list:
    How to do it…
  2. Click on Next.
  3. Select country, city, line, and totalPrice from the available fields and add these fields to the selected fields' area by clicking on the arrow next to the Selected box. These are the fields we want to add to the report.
  4. Change the order of these fields so that they are listed from top to bottom as country, city, line, and totalPrice:
    How to do it…
  5. Click on Finish to exit the Report Wizard.

How it works…

The Report Wizard allows us to simply create a query and configure it to return the correct data in a couple of steps. Once we have the data from the query, we can then select what fields will be included in the report. With the query and report defined in the Report Wizard, we will be able to generate a report in the Pentaho Report Designer that will get us quickly started. From this point, we are free to edit the generated report further using the various tools that come with the Pentaho Report Designer.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset