This page provides you with instructions on how to extract data from MongoDB and analyze it in Google Data Studio. (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 Google Data Studio?
Google Data Studio is a simple dashboard and reporting tool. It's free and easy to use, but it lacks the sophisticated features of higher-end reporting software. Many of the connectors it supports are for Google products, but third parties have written partner connectors to a wide variety of data sources. Its drag-and-drop report editor lets users create about 15 types of charts.
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 Google Data Studio
Google Data Studio uses what it calls "connectors" to gain access to data. Data Studio comes bundled with 17 connectors, mostly to pull in data from other Google products. It also supports connectors to MySQL and PostgreSQL databases, and offers 200 connectors to other data sources built and supported by partners.
Using data in Google Data Studio
Google Data Studio provides a graphical canvas onto which users drag and drop datasets. Users can set dimensions and metrics, specify sorting and filtering, and tailor the way reports and charts are displayed.
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 Google Data Studio is to store that data inside a data warehousing platform alongside data from your other databases and third-party sources. You can find instructions for doing these extractions for leading warehouses on our sister sites MongoDB to Redshift, MongoDB to BigQuery, MongoDB to Azure Synapse Analytics, MongoDB to PostgreSQL, MongoDB to Panoply, and MongoDB to Snowflake.
Easier yet, however, is using a solution that does all that work for you. Products like Stitch were built to move data automatically, making it easy to integrate MongoDB with Google Data Studio. With just a few clicks, Stitch starts extracting your MongoDB data, structuring it in a way that's optimized for analysis, and inserting that data into a data warehouse that can be easily accessed and analyzed by Google Data Studio.