Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migration of unmigrated content due to installation of a new plugin
Wiki Markup
{scrollbar}
{
}
Excerpt

How

to

create

a

report

that

uses

data

from

a

collection

in

MongoDB.

{excerpt}

By

...

the

...

end

...

of

...

this

...

guide

...

you

...

should

...

understand

...

how

...

data

...

can

...

be

...

read

...

from

...

MongoDB

...

and

...

used

...

in

...

a

...

report.

...

The

...

data

...

we

...

are

...

going

...

to

...

use

...

contains

...

data

...

about

...

the

...

flow

...

of

...

visitors

...

to

...

a

...

web

...

site.

...

This

...

guide

...

shows

...

how

...

to

...

create

...

a

...

report

...

that

...

shows

...

the

...

most

...

popular

...

landing

...

pages

...

for

...

the

...

sample

...

web

...

site.

...

Intro Video

Widget Connector
width600
urlhttps://www.youtube.com/watch?v=qgOYtZ77ZHo
height480

Prerequisites

In order follow along with this how-to guide you will need the following:

MongoDB

A single-node local cluster is sufficient for these exercises but a larger and/or remote configuration will work as well. You will need to know the address and port that MongoDB is running on and have a user id and password for the server (if applicable).
These guides were developed using the MongoDB version 2.0.2.

...

You

...

can

...

find

...

MongoDB

...

downloads

...

here:

...

http://www.mongodb.org/downloads

...

Kettle

A desktop installation of the Kettle design tool called 'Spoon'.

...

Download

...

here.

...

Pentaho Report Designer

Pentaho Report Designer (PRD)

...

is

...

a

...

desktop

...

tool

...

for

...

creating

...

highly

...

formatted

...

reports

...

that

...

can

...

be

...

exported

...

to

...

many

...

popular

...

formats.

...

Reports

...

created

...

with

...

PRD

...

can

...

be

...

published

...

to

...

a

...

Pentaho

...

BI

...

Server

...

so

...

they

...

can

...

be

...

accessed

...

using

...

a

...

browser.

...

Download

...

here.

...

Data

To follow this guide you need to have a populated MongoDB collection. If you do not have any data in MongoDB yet you can use the Write Data To MongoDB guide to add some data to your MongoDB installation. The instructions in this guide assume that the demo data set is available in a collection called PageSuccessions in a database called Demo.

Step-By-Step Instructions

We will create the report using two tools. First we will use Spoon to create a data transformation that selects data from MongoDB and sorts it into descending order. Then we will use PRD to create a report using the data transformation as its data source.

Setup

Start MongoDB if is not running.

Create a Data Transformation

Start Spoon on your desktop. Once it is running choose 'File' -> 'New' -> 'Transformation' from the menu system or click on the 'New file' icon on the toolbar and choose the 'Transformation' option.

Tip
titleSpeed Tip

You can download the Kettle Transform top_landing_pages.ktr already completed

  1. Add a MongoDB Input Step: We are going to read data from MongoDB, so expand the 'Big Data section of the Design palette and drag a 'MongoDb Input' step onto the transformation canvas.
    Image Added
  2. Edit the MongoDb Input Step: Double-click on the 'MongoDb Input' step to edit its properties. Enter this information:
    1. Host name, Port, Authentication user and password: the connection information for your MongoDB installation.
    2. Database: 'Demo' or another database if you want.
    3. Collection: 'PageSuccessions'
    4. Query expression: { "$query" : { "url" : "--firstpage--" }, "$orderby" : { "Count" : -1 } }
      The window should look like this:
      Image Added
      Click 'OK' to close the 'MongoDB Input' window.
  3. Preview the Data: Click on the Preview toolbar button (the green arrow with the magnifying glass Image Added ) or right-click on the step and choose 'Preview'. The 'Transformation debug dialog' will open. Click on 'Quick Launch'. You will should see the data returned by the 'MongoDB Input' step.
    Image Added
    Congratulations! You've read data from MongoDB. Close the preview window.
  4. Add a JSON Input Step: The data from the 'MongoDB Input' step has a JSON document in each row. To work with the data in these documents we need to use a 'JSON Input' step to extract the fields that we are interested in. Expand the 'Input' section and drag a 'JSON Input' step onto the canvas.
    Image Added
  5. Connect the MongoDB and JSON Steps: Hover the mouse over the 'MongoDb Input' step and a tooltip will appear. Image Added Click on the output connector (the green arrow pointing to the right) and drag a connector arrow to the 'Json Input' step. Your canvas should look like this: Image Added
  6. Edit the JSON Step: Double-click on the 'Json Input' step to edit it's properties. On the 'File' tab choose 'json' from the 'Get source from field' dropdown list.
    Image Added
    On the 'Fields' tab, enter this information:
    Image Added
    Click 'OK' to close the 'Json input' window.
  7. Preview the JSON Input: Preview the 'Json Input' step as we did about with the 'MongoDb Input' step. You will see the JSON documents as before, but if you scroll the table to the right you will see new fields for URL, NextURL, and Count.
    Image Added
    Notice the data is sorted into descending order by the Count field. Close the preview window.
  8. Save the Transformation: Choose 'File' -> 'Save as...' from the menu system. Save the transformation as 'top_landing_pages.ktr'

...

  1. into

...

  1. a

...

  1. folder

...

  1. of

...

  1. your

...

  1. choice.

...

  1. Run

...

  1. the

...

  1. Transformation

...

  1. :

...

  1. Choose

...

  1. 'Action'

...

  1. ->

...

  1. 'Run'

...

  1. from

...

  1. the

...

  1. menu

...

  1. system

...

  1. or

...

  1. click

...

  1. on

...

  1. the

...

  1. green

...

  1. run

...

  1. button

...

  1. on

...

  1. the

...

  1. transformation

...

  1. toolbar.

...

  1. A

...

  1. 'Execute

...

  1. a

...

  1. transformation'

...

  1. window

...

  1. will

...

  1. open.

...

  1. Click

...

  1. on

...

  1. the

...

  1. 'Launch'

...

  1. button.

...

  1. An

...

  1. 'Execution

...

  1. Results'

...

  1. panel

...

  1. will

...

  1. open

...

  1. at

...

  1. the

...

  1. bottom

...

  1. of

...

  1. the

...

  1. Spoon

...

  1. window

...

  1. and

...

  1. it

...

  1. will

...

  1. show

...

  1. you

...

  1. the

...

  1. progress

...

  1. of

...

  1. the

...

  1. transformation

...

  1. as

...

  1. it

...

  1. runs.

...

  1. After

...

  1. a

...

  1. few

...

  1. seconds

...

  1. the

...

  1. transformation

...

  1. should

...

  1. finish

...

  1. successfully:

...


  1. Image Added
    If any errors occurred the transformation step that failed will be highlighted in red and you can use the 'Logging' tab to view error messages.

    Start Pentaho Report Designer

    When PRD starts click on the 'Report Wizard' button or choose 'File' -> 'Report Wizard...'

...

  1. from

...

  1. the

...

  1. menu.

...

  1. Select

...

  1. a

...

  1. Template

...

  1. :

...

  1. On

...

  1. the

...

  1. 'Look

...

  1. and

...

  1. Feel'

...

  1. stage

...

  1. of

...

  1. the

...

  1. wizard

...

  1. select

...

  1. a

...

  1. report

...

  1. template

...

  1. and

...

  1. click

...

  1. on

...

  1. 'Next'

...

  1. Add

...

  1. a

...

  1. Data

...

  1. Source

...

  1. :

...

  1. On

...

  1. the

...

  1. 'Data

...

  1. Source'

...

  1. stage

...

  1. click

...

  1. on

...

  1. the

...

  1. '+'

...

  1. icon

...

  1. in

...

  1. the

...

  1. top

...

  1. right

...

  1. to

...

  1. add

...

  1. a

...

  1. new

...

  1. data

...

  1. source.

...

  1. Choose

...

  1. the

...

  1. Data

...

  1. Source

...

  1. Type

...

  1. :

...

  1. From

...

  1. the

...

  1. 'Choose

...

  1. Type'

...

  1. list

...

  1. click

...

  1. on

...

  1. 'Pentaho

...

  1. Data

...

  1. Integration'.

...


  1. Image Added
  2. Add a Query: In the 'Pentaho Data Integration Data Source' window click on the '+' icon to add a new query. A default query, called 'Query 1' is added. Change the name of the query to 'Top Landing Pages'. Then click on the 'Browse' button and select the 'top_landing_pages.ktr'

...

  1. file

...

  1. created

...

  1. above.

...

  1. Finally

...

  1. select

...

  1. the

...

  1. 'Json

...

  1. Input'

...

  1. step.

...


  1. Image Added
    If you want you can click the 'Preview'

...

  1. button

...

  1. to

...

  1. see

...

  1. the

...

  1. data

...

  1. generated

...

  1. by

...

  1. the

...

  1. 'Json

...

  1. Input'

...

  1. step.

...

  1. Click

...

  1. on

...

  1. 'OK'

...

  1. to

...

  1. close

...

  1. the

...

  1. 'Pentaho

...

  1. Data

...

  1. Integration

...

  1. Data

...

  1. Source'

...

  1. window.

...

  1. Select

...

  1. the

...

  1. Query

...

  1. :

...

  1. In

...

  1. the

...

  1. 'Report

...

  1. Design

...

  1. Wizard'

...

  1. click

...

  1. on

...

  1. the

...

  1. 'Top

...

  1. Landing

...

  1. Pages'

...

  1. query

...

  1. to

...

  1. select

...

  1. it

...

  1. and

...

  1. then

...

  1. click

...

  1. on

...

  1. the

...

  1. 'Next'

...

  1. button.

...

  1. Layout

...

  1. the

...

  1. Fields

...

  1. :

...

  1. In

...

  1. the

...

  1. 'Layout

...

  1. Step'

...

  1. of

...

  1. the

...

  1. wizard

...

  1. click

...

  1. on

...

  1. 'NextURL'

...

  1. then

...

  1. click

...

  1. on

...

  1. the

...

  1. button

...

  1. to

...

  1. add

...

  1. 'NextURL'

...

  1. to

...

  1. the

...

  1. 'Selected

...

  1. Items'

...

  1. box.

...

  1. Now

...

  1. add

...

  1. 'Count'

...

  1. to

...

  1. the

...

  1. 'Selected

...

  1. Items'

...

  1. box.

...

  1. This

...

  1. will

...

  1. position

...

  1. these

...

  1. two

...

  1. fields

...

  1. as

...

  1. two

...

  1. columns

...

  1. in

...

  1. the

...

  1. report.

...


  1. Image Added
    Click on the 'Next'

...

  1. button.

...

  1. Format

...

  1. the

...

  1. Fields

...

  1. :

...

  1. In

...

  1. this

...

  1. step

...

  1. you

...

  1. can

...

  1. change

...

  1. the

...

  1. formatting

...

  1. of

...

  1. the

...

  1. fields.

...

  1. Click

...

  1. on

...

  1. the

...

  1. 'NextURL'

...

  1. field

...

  1. to

...

  1. highlight

...

  1. it.

...

  1. Change

...

  1. the

...

  1. Display

...

  1. Name

...

  1. to

...

  1. 'Web

...

  1. Page'.

...

  1. Then

...

  1. click

...

  1. on

...

  1. 'Count'

...

  1. to

...

  1. highlight

...

  1. it.

...

  1. Change

...

  1. the

...

  1. data

...

  1. format

...

  1. to

...

  1. '#,###;(#,###)'

...

  1. and

...

  1. select

...

  1. 'Sum'

...

  1. from

...

  1. the

...

  1. 'Aggregation'

...

  1. list.
    Image Added
  2. Finish the Wizard: Click on 'Finish'.

...

  1. The

...

  1. wizard

...

  1. will

...

  1. close

...

  1. and

...

  1. you

...

  1. will

...

  1. see

...

  1. your

...

  1. report

...

  1. in

...

  1. design

...

  1. mode.
    Image Added
  2. Change the Titles: Double-click

...

  1. on

...

  1. the

...

  1. report

...

  1. title

...

  1. and

...

  1. change

...

  1. it

...

  1. to

...

  1. 'Top

...

  1. Landing

...

  1. Pages'.

...

  1. Double-click

...

  1. on

...

  1. the

...

  1. first

...

  1. subtitle

...

  1. and

...

  1. change

...

  1. it

...

  1. to

...

  1. 'In

...

  1. descending

...

  1. order'.

...

  1. Double-click

...

  1. on

...

  1. the

...

  1. second

...

  1. subtitle

...

  1. and

...

  1. remove

...

  1. the

...

  1. text.

...

  1. Notice

...

  1. that

...

  1. there

...

  1. are

...

  1. lot

...

  1. of

...

  1. style

...

  1. properties

...

  1. you

...

  1. can

...

  1. set

...

  1. for

...

  1. these

...

  1. report

...

  1. elements.

...

  1. Preview

...

  1. the

...

  1. Report

...

  1. :

...

  1. Click

...

  1. on

...

  1. the

...

  1. preview

...

  1. icon

...

  1. (the

...

  1. eye

...

  1. towards

...

  1. the

...

  1. top

...

  1. left)

...

  1. to

...

  1. preview

...

  1. your

...

  1. report.

...

  1. Notice

...

  1. that

...

  1. the

...

  1. rows

...

  1. of

...

  1. data

...

  1. are

...

  1. sorted

...

  1. into

...

  1. descending

...

  1. order.

...

  1. You

...

  1. can

...

  1. page

...

  1. through

...

  1. the

...

  1. report.

...

  1. At

...

  1. the

...

  1. end

...

  1. of

...

  1. the

...

  1. last

...

  1. page

...

  1. you

...

  1. will

...

  1. see

...

  1. the

...

  1. total

...

  1. for

...

  1. the

...

  1. page

...

  1. counts.

...


  1. Image Added
    Click on the design icon (where the preview icon used to be) to return to design mode.
  2. Run or Export the Report: Click on the run button (green arrow on the toolbar) or choose 'File' -> 'Export' from the menu system. Select the output format for your report. If you used the run button the report will run and the appropriate application will be opened to view the report. If you chose the export option you will be prompted for the location and name of the file that will be exported.

Check The Results

  1. Using the run or export options you will be able to create and view PDF, Excel, HTML, and other file types. Try these options and check that the exported files contain the expected data.

Summary

During this guide you learned how to read data from a MongoDB collection and use it as the data source for a report.
Other guides in this series cover to sort and group MongoDB data, and combine data from MongoDB with data from other sources.

Wiki Markup
{scrollbar}