Connecting to MongoDB via PDI

In this recipe, we will guide you through the steps required to connect to a MongoDB instance using a Pentaho Data Integration transformation and execute that transformation in a Pentaho Report.

Getting ready

To get ready for this recipe, you will have to make sure your MongoDB instance is running.

How to do it…

For this recipe, we are going to use a transformation that we have already developed for the book that will return a list of orders as shown in the previous recipe. We are also going to build this report manually instead of using the Report Wizard:

  1. In Report Designer, go to File | New.
  2. Click on the Data tab in the top-right corner of Report Designer.
  3. Right-click on the Data item in the list and select Pentaho Data Integration:
    How to do it…
  4. Just like previously in the Report Wizard, we are going to create our data source:
    1. To add a new data source, click on the Plus Icon in the top-left corner of the pop-up window.
    2. Set the Name property of the query to Orders.
    3. Click on the Browse button to open the select transformation dialog.
    4. Browse to the chapter 5 folder and select the chapter5-getorders.ktr transformation. (This file is provided as source code along with this book.)
    5. Select the OUT step in the list of steps available in this transformation:
      How to do it…
    6. Click on Preview, as shown in the preceding screenshot. The Preview window shows up as seen in the following screenshot:
      How to do it…
    7. Click on OK.

We have now chosen our data source. We can see the fields that are available to us in the Data tab of Report Designer:

How to do it…

The next step is to get these fields into the report. To do this, we will follow these simple steps:

  1. Click and drag the country field from the Data tab and drop it into the Details band of the report, just to make sure that the item is aligned to the top-left side of the Details band.
  2. Click and drag the city field to sit next to the country field in the Details band. If the items overlap in the Details band, then the item background color will turn pink. This is to inform you that you have overlapping items in the report.
  3. Finally, click and drag the remaining line and totalPrice fields into the report and set them alongside the previous fields. Once the items are in the correct position, you should be looking at something that will be similar to the following screenshot:
    How to do it…
  4. Click on Preview and the following report appears:
    How to do it…

How it works…

This report simply executes a Pentaho Data Integration that connects to a MongoDB data source to return data. Once the data is in the report, we can define what fields we want to display from the transformation in our report.

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

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