This page provides you with instructions on how to extract data from MongoDB and analyze it in Amazon QuickSight. (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 QuickSight?
Amazon QuickSight is the AWS business intelligence tool for creating dashboards and visualizations. Users are charged per session only for the time when they access dashboards or reports. QuickSight supports a variety of data sources, such as individual databases (Amazon Aurora, MariaDB, and Microsoft SQL Server), data warehouses (Amazon Redshift and Snowflake), and SaaS sources (Adobe Analytics, GitHub, and Salesforce), along with several common standard file formats.
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 QuickSight
You must replicate data from your SaaS applications to a data warehouse (such as Redshift) before you can report on it using QuickSight. Once you specify a data source you want to connect to, you must specify a host name and port, database name, and username and password to get access to the data. You then choose the schema you want to work with, and a table within that schema. You can add additional tables by specifying them as new datasets from the main QuickSight page.
Using data in QuickSight
QuickSights provides both a visual report builder and the ability to use SQL to select, join, and sort data. QuickSight lets you combine visualizations into dashboards that you can share with others, and automatically generate and send reports via email.
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 Amazon QuickSight 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 Amazon QuickSight. 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 Amazon QuickSight.