MongoDB aggregations provide an effective method for summarizing data in order to identify trends, understand changes over time, and in other ways gain insights into that data. Studio 3T makes it easy to create a wide range of aggregations, especially with the help of the Aggregation Editor. But aggregations are useful only if analysts, decision-makers, and other key players can access and understand that information. Fortunately, Studio 3T provides multiple tools to help you get the data into the hands of the people who need it.
In this section, you’ll learn how to use Studio 3T features to make your aggregated data available to other users and applications. You’ll start by saving the results of an aggregation query to a view. You’ll also export a collection to a .csv file and then open the file in Microsoft Excel, where you can organize and visualize the data. In addition, you’ll learn how to use MongoDB Charts to visualize data in a collection you create in Studio 3T.
By the end of this section, you will learn how to
- Create a view based on an aggregation query
- Export a collection as a .csv file for use by a third-party tool
- Visualize collection data in MongoDB Charts
What you will need
- Ability to download a .json file from the internet
- Ability to open a .csv file in Microsoft Excel
- Access to a MongoDB Atlas cluster and to MongoDB Charts
Making aggregated data available to users and applications
A MongoDB view is a database object that can be queried just like a collection, except that the view does not persist the data. You can think of a view as a saved query, similar to views in a relational database. When a client application queries the view, MongoDB runs the query and returns the results.
A view provides an easy way to enable applications to access aggregated data without needing to write complex queries. A view also limits an application’s visibility into a database, restricting access to only a specific subset of data in a collection, rather than exposing the entire collection.
The Aggregation Editor in Studio 3T makes it very easy to create a view based on the active
aggregate statement. After you build your statement and ensure that it returns the desired results, you can create a view in a few simple steps: right-click anywhere in the Pipeline flow window or Pipeline output window, click Create view from this Aggregate Query, provide a name for the view, and click OK.
That’s all there is to creating a view. After that, an authorized user or application can retrieve data from that view by running a simple find operation. In this way, an organization can provide the aggregated data to the people who need it, whether the data is delivered through a dashboard, an embedded report, a visualization tool, or some other mechanism.
In addition to views, Studio 3T also makes it easy to export collection data to the CSV format, as well as to formats such as JSON or SQL. The CSV format is especially handy because of its universal nature, having been used by countless applications over the years to exchange data. For example, you can export a collection as a .csv file and then open the file in Microsoft Excel, where you can format, filter, and sort the data, as well as create rich visualizations based on that data. You can also use .csv files to import data into applications such as Tableau, Salesforce, Zoho Analytics, SAP Analytics Cloud, Microsoft Power BI Desktop, and many others.
To export a collection’s data to a .csv file, you need only right-click the collection in the Connection Tree and click Export Collection, which launches the Export wizard. In the wizard’s first screen, you select the CSV option and then click Configure, which opens the Export tab, as shown in the following figure.
On this tab, you can configure a number of settings that control how the data is exported to the .csv file. For example, you can select which fields to include, what type of delimiter to use (instead of the default comma), how to encapsulate complex values, which record separator to use, and other settings. Studio 3T will then save the file to the designated location, where you can make it available to Excel or other applications for visualizing the data or working with it in other ways.
Another option for visualizing collection data is to take advantage of MongoDB Charts, which provides a user-friendly interface for creating visualizations based on MongoDB data. The tool lets you create a wide range of charts that provide quick insights into the underlying data. If you’re already connected to MongoDB Atlas when creating your collections in Studio 3T, those collections are automatically available to MongoDB Charts, making it easy to start visualizing data directly through your browser.Next – Exercise 1: Creating a view based on an aggregation query