Using MongoDB with Community Data Access (CDA)

I’ve covered how to get data directly from MongoDB directly into Pentaho Reports.  But what if you want to get them in a dashboard built with Community Dashboard Framework (CDF)?  That’s actually about as simple as getting it into a Pentaho report.

CDF comes with a related technology known as Community Data Access (CDA).  In general, CDA is a technology that abstracts access to data and provides a consistent approach to data access for CDF dashboards.  Among it’s other nice features are that it supports a wide variety of data sources including scripting.  Currently the scripting data source only supports Beanshell, but that’s good enough for communicating with MongoDB.

I’ve used the same database and collection from the reporting example, so you can find the source there.  I won’t go into all of the details of the CDA since you can find those at the WebDetails site.  The significant pieces are that you need to have a Connection of type “scripting.scripting” and then a DataAccess of type “scripting”.  As you can see, the query script is essentially the same as the one for reporting except that it’s in the Beanshell syntax.

<?xml version="1.0" encoding="UTF-8"?>
<CDADescriptor>
 <DataSources>
 <Connection id="mongodb" type="scripting.scripting">
 <Language>beanshell</Language>
 <InitScript/>
 </Connection>
 </DataSources>
 <DataAccess access="public" cache="true" cacheDuration="3600" connection="mongodb" id="mongodb-sales" type="scriptable">
   <Name>Sales via MongoDB</Name>
   <Columns/>
   <Parameters/>
   <Query><![CDATA[
import com.mongodb.*;
import org.pentaho.reporting.engine.classic.core.util.TypedTableModel;
Mongo mongo = new Mongo();
db = mongo.getDB("pentaho");
sales = db.getCollection("sales");
String [] columnNames = {"Region", "Year", "Q1", "Q2", "Q3", "Q4"};
Class[] columnTypes = {String.class, Integer.class, Integer.class, Integer.class, Integer.class, Integer.class};
TypedTableModel model = new TypedTableModel(columnNames, columnTypes);
docs= sales.find();
while (docs.hasNext()) {
 doc = docs.next();
 model.addRow(new Object[] { doc.get("region"), doc.get("year"), doc.get("q1"), doc.get("q2"), doc.get("q3"), doc.get("q4")});
}
docs.close();
return model;
 ]]></Query>
 </DataAccess>
</CDADescriptor>

Now that the CDA data access has been defined you can use the CDA previewer to view the results.  Assuming you’ve used the same data you should see something similar to the following:

Example of the data from MongoDB via CDA.

At this point the data is available for any dashboard that has permission to access the data.

 


2 Comments on “Using MongoDB with Community Data Access (CDA)”

  1. sadakarar says:

    Hi.. thank you for the post.. could you tell us how we can use step of mongo db designed in ktr in pentaho CDE dashboard ?

    • billdback says:

      I’m not a CDE expert, so I can’t really say. I notice you have been asking this question on several different forums. I also noticed that I was able to find some examples in a few blogs rather quickly. I would recommend doing a search for “Community Dashboard Editor transformation” and trying out what you find.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 295 other followers