MongoDB to Tableau

This page provides you with instructions on how to extract data from MongoDB and analyze it in Tableau. (If the mechanics of extracting data from MongoDB seem too complex or difficult to maintain, check out Stitch, which can do all the heavy lifting for you in just a few clicks.)

What is MongoDB?

MongoDB, or just Mongo, is an open source NoSQL database that stores data in JSON format. It uses a document-oriented data model, and data fields can vary by document. MongoDB isn't tied to any specified data structure, meaning that there's no particular format or schema for data in a Mongo database.

What is Tableau?

Tableau is one of the world's most popular analysis platforms. The software helps companies model, explore, and visualize their data. It also offers cloud capabilities that allow analyses to be shared via the web or company intranets, and its offerings are available as both installed software and as a SaaS platform. Tableau is widely known for its robust and flexible visualization capabilities, which include dozens of specialized chart types.

In addition to its business software, Tableau also offers a free product called Tableau Public for analyzing open data sets. If you're new to Tableau, this offering is a great way to experience Tableau's capabilities at no cost and share your work publicly.

Getting data out of MongoDB

The process of pulling data out of MongoDB depends on how you've loaded data into MongoDB. In some cases, it may be impossible to extract all of your data, because NoSQL databases don't require structure (i.e. specific columns). Relational databases, such as those used for data warehouses, use a more traditional, rigid structure. You'll need to defined a structure in the relational database into which you can insert MongoDB data.

Don't stress about the confusing data structure. Lots of the data that's loaded into MongoDB is created by a computer, so it probably has a pretty predictable structure. If you can find specific fields that exist for every record, you're well on your way. Make sure these fields appear in the records of each collection you'd like to replicate from MongoDB. There are many ways to do this. The most popular method to get data from MongoDB is to use the find() command.

Sample MongoDB data

MongoDB stores and returns JSON-formatted data. Here's an example of what a response might look like to a query against the products collection.

db.products.find( { qty: { $gt: 25 } }, { _id: 0, qty: 0 } )

{ "item" : "pencil", "type" : "no.2" }
{ "item" : "bottle", "type" : "blue" }
{ "item" : "paper" }

Loading Data into Tableau

Analyzing data in Tableau requires putting it into a format that Tableau can read. Depending on the data source, you may have options for achieving this goal, but the best practice among most businesses is to build a data warehouse that contains the data, and then connect that data warehouse to Tableau.

Tableau provides an easy-to-use Connect menu that allows you to connect data from flat files, direct data sources, and data warehouses. In most cases, connecting these sources is simply a matter of creating and providing credentials to the relevant services.

Once the data is connected, Tableau offers an option for locally caching your data to speed up queries. This can make a big difference when working with slower database platforms or flat files, but is typically not necessary when using a scalable data warehouse platform. Tableau's flexibility and speed in these areas are among its major differentiators in the industry.

Analyzing Data in Tableau

Tableau's report-building interface may seem intimidating at first, but it's one of the most powerful and intuitive analytics UIs on the market. Once you understand its workflow, it offers fast and nearly limitless options for building reports and dashboards.

If you're familiar with Pivot Tables in Excel, the Tableau report building experience may feel somewhat familiar. The process involves selecting the rows and columns desired in the resulting data set, along with the aggregate functions used to populate the data cells. Users can also specify filters to be applied to the data and choose a visualization type to use for the report.

You can learn how to build a report from scratch for free (although a sign-in is required) from the Tableau documentation.

Keeping MongoDB data up to date

Fine job! You are the proud developer of a script that moves data from MongoDB to your data warehouse. This works as a one-shot deal. It's good to think about what will happen when there is new and updated data in MongoDB.

One option that works would be to load the entire MongoDB dataset all over again. That would certainly update the data, but it's not very efficient and can also cause terribly latency.

The smartest way to get data updated from MongoDB would be to identify keys that can be used as bookmarks to store where you script left off on the last run. Fields like updated_at, modified_at, or other auto-incrementing data are useful here. With that done, you can set up your script as a cron job or continuous loop to identify new data as it appears.

From MongoDB to your data warehouse: An easier solution

As mentioned earlier, the best practice for analyzing MongoDB data in Tableau is to store that data inside a data warehousing platform alongside data from your other databases and 3rd party sources. You can find instructions for doing these extractions for leading warehouses on our sister sites MongoDB to Redshift, MongoDB to BigQuery, and MongoDB to Snowflake.

Easier yet, however, is using a solution that does all that work for you. Products like Stitch were built to solve this problem automatically. With just a few clicks, Stitch starts extracting your MongoDB data via the API, structuring it in a way that is optimized for analysis, and inserting that data into a data warehouse that can be easily accessed and analyzed by Tableau.