Skip to content
Studio 3T - The professional GUI, IDE and client for MongoDB
  • Tools
    • Aggregation Editor
    • IntelliShell
    • Visual Query Builder
    • Export Wizard
    • Import Wizard
    • Query Code
    • SQL Query
    • Connect
    • Schema Explorer
    • Compare
    • SQL ⇔ MongoDB Migration
    • Data Masking
    • Task Scheduler
    • Reschema
    • More Tools and Features
  • Solutions
  • Resources
    • Knowledge Base
    • MongoDB Tutorials & Courses
    • Tool/Feature Documentation
    • Blog
    • Community
    • Testimonials
    • Whitepapers
    • Reports
  • Contact us
    • Contact
    • Sales Support
    • Feedback and Support
    • Careers
    • About Us
  • Store
    • Buy Now
    • Preferred Resellers
    • Team Pricing
  • Download
  • My 3T
search

Academy 3T

  • Explore our courses
    • MongoDB 101: Getting Started
    • MongoDB 201: Querying MongoDB Data
    • MongoDB 301: Aggregation
  • Get certified

Exercise 3: Visualizing collection data in MongoDB Charts

MongoDB 301: Aggregation Reporting with Studio 3T Aggregations Exercise 3: Visualizing collection data in MongoDB Charts

In this exercise, you’ll use IntelliShell to run an aggregate statement that will output the results to a new collection. The statement will remove some of the customers’ personal information, such as their names, email addresses, and dates of birth. You’ll then use this collection in MongoDB Charts to create a column chart based on the sales of a specific user.

To visualize the collection data

  1. On the IntelliShell tab, replace the existing aggregate statement with the following statement:
db.customers_txn.aggregate( [
  { 
    "$unset": [ "title", "first", "last", "email", "dob" ]
  },
  {
    "$match": { "user_name": { "$exists": true, "$ne": null } }
  },
  { 
    "$out": { "db": "sales", "coll": "customers_clean" }
  }
] );

The aggregate statement includes three stages:

  • The first stage uses the $unset operator to remove the title, first, last, email, and dob fields.
  • The second stage uses the $match operator to remove any documents whose user_name field is null.
  • The third stage uses the $out operator to save the query results to the customers_clean collection in the sales database.
  1. On the IntelliShell toolbar, click the Run button. The query results are displayed in the lower pane, as shown in the following figure.
  1. In the Connection Tree, expand the sales database node and Collections node, if necessary, and confirm that the customers_clean collection has been created. You might need to refresh the list of collections. You can also open the collection to make certain it’s been created as you expected.
  2. Sign into the MongoDB website and navigate to the Charts page.
  3. You must have at least one dashboard in place before you can create a chart. Normally, a dashboard is created by default, but if a dashboard does not exist, you will need to create it now. The following figure shows the Dashboard tab on the Charts page with one dashboard created. The dashboard is named Customer Sales.
  1. Go to the Data Sources tab and click Add Data Source.
  2. In the Add Data Sources wizard, select the cluster that contains the sales database and customers_clean collection, and then click Next. The wizard will process the request and then display a list of databases and collections. This process can take up to one minute.
  3. When the list appears, select the customers_clean collection node, and then click Finish. The Data Sources tab should now display the collection, along with any other data sources that have been set up. The following figure shows the Data Sources tab with two collections, one of which is sample data provided by MongoDB.
  1. Return to the Dashboards tab and click the name of the dashboard where you want to add the chart. This opens the dashboard.
  2. Click the Add Chart button.
  3. On the Add Chart page, select Column from the Chart Type drop-down list, and then select Grouped, if it’s not already selected.
  4. From the Data Source drop-down list, select sales.customers_clean. Charts adds the fields to the left pane,
  5. In the Query text box, paste the following expression:
[ { "$unwind": { "path":"$payments" } } ]

The expression applies the $unwind aggregate operator to the source data to unwind the payments array, which will make it easier to work with the date values in that array.

  1. Click the Apply button to the right of the text box. MongoDB Charts will apply the expression and update the information in the left pane.
  2. Select the Filter tab in the middle pane.
  3. Expand the address field node in the left pane and drag the state field to the + filter placeholder in the Filter section in the middle pane. This loads all the state values into the Filter section, where you can choose which states to include in the results.
  4. Clear all checkboxes and then select Washington. If Washington is not listed, click the + Add value link, type Washington in the text box, and click the check icon.
  5. Click the ^ hide link to minimize the state filter.
  6. From the left pane, drag the user_name field to the + filter placeholder in the Filter section. This loads all the user_name values into the Filter section, where you can choose which usernames to include in the results.
  7. Clear all check boxes and then select bfreemanl. If bfreemanl is not listed, click the + Add value link, type bfreemanl in the text box, and click the check icon.
  8. Click the ^ hide link to minimize the user_name filter. The middle pane should now look like the following figure.
  1. Go to the Encode tab in the middle pane.
  2. From the left pane, drag the user_name field to the + category placeholder in the X Axis area of the Encode section.
  3. In the Sort by drop-down list in the X Axis area, select CATEGORY. The X Axis settings should now look like the following figure.
  1. In the left pane, expand the payments node and then drag the value field to the + aggregation placeholder in the Y Axis area of the Encode section. The SUM option should be selected in the Aggregate drop-down list, as shown in the following figure.

At this point, an initial chart will be displayed in the main window, although it still has little meaning.

  1. From the left pane, drag the date field to the + category placeholder in the Series area of the Encode section. This should enable the Binning option by default, with MONTH selected in the drop-down list.

Configuring the series will update the chart, but it’s still cluttered looking.

  1. Return to the Filter tab in the middle pane.
  2. From the left pane, drag the date field to the + filter placeholder in the Filter section. You’ll be presented with several configuration options for setting the date.
  3. In the date filter, select the Absolute option and then enable the From and To options.
  4. In the From box, set the date to 01/01/2020, set the time to 12:00:00 AM, and select the Inclusive check box.
  5. In the To box, set the date to 01/01/2021 and set the time at 12:00:00 AM. Do not select the Inclusive check box.
  6. Go to the Customize tab in the middle pane.

The Customize tab includes a number of options for controlling how the chart should look. The following steps walk you through several options, but feel free to experiment with these settings however you like.

  1. In the Axes section, set the Label Angle to HORIZONTAL.
  2. In the Fields section, select user_name, enable Label Override, and type Customer as the new label.
  3. In the Fields section, select payments.date, enable Label Override, and type Month key as the new label.
  4. In the Fields section, select sum ( payments.value ), enable Label Override, and type Total Payments as the new label. 
  5. Add a title and description to the chart, which should now look similar to the following figure.
  1. Click Save. This will return you to the dashboard, where you can resize the report and view specific information by hovering over the bars or clicking months in the key. The following figure shows the Customer Sales dashboard with the 2020 Sales Report chart.
  1. Log out of the MongoDB website.
  2. Return to Studio 3T and close the IntelliShell tab. If prompted to save changes, click No, Discard.
  3. Close Studio 3T.

Quizzes
Reporting with Studio 3T Aggregations: Test your skills
Previous Topic
Back to Lesson
Next Quiz
  • Course Home Expand All
    Building a Basic Aggregation
    4 Topics | 1 Quiz
    Exercise 1: Filtering the documents in the aggregation pipeline
    Exercise 2: Grouping the documents in the aggregation pipeline
    Exercise 3: Sorting the documents in the aggregation pipeline
    Exercise 4: Adding processing options to the aggregation
    Building a Basic Aggregation: Test your skills
    Introducing the Aggregation Editor
    4 Topics | 1 Quiz
    Exercise 1: Importing an aggregate statement into the Aggregation Editor
    Exercise 2: Replace a field in the aggregation pipeline
    Exercise 3: Reorder the fields in the aggregation pipeline
    Exercise 4: Changing the sort order in the aggregation pipeline
    Introducing the Aggregation Editor: Test your skills
    Working with Arrays in the Aggregation Pipeline
    5 Topics | 1 Quiz
    Exercise 1: Using expression operators to filter input documents
    Exercise 2: Unwinding an array to create individual documents
    Exercise 3: Grouping array values and generating a document count for each group
    Exercise 4: Writing pipeline results to a new collection
    Working with Arrays in the Aggregation Pipeline: Test your skills
    MongoDB 301 Mid-Course Feedback
    Adding Lookup Data to the Aggregation Pipeline
    4 Topics | 1 Quiz
    Exercise 1: Adding lookup data to the aggregation pipeline
    Exercise 2: Converting string values in one of the lookup fields to integers
    Exercise 3: Adding a computed ratio field based on the converted lookup field
    Exercise 4: Limiting the number of returned documents
    Adding Lookup Data to the Aggregation Pipeline: Test your skills
    Working with Reschema for MongoDB
    4 Topics | 1 Quiz
    Exercise 1: Setting up a reschema unit that includes lookup data
    Exercise 2: Defining a target collection in the reschema unit
    Exercise 3: Adding and scheduling a task to create the target collection
    Exercise 4: Running an aggregate statement against the target collection
    Working with Reschema for MongoDB: Test your skills
    Reporting with Studio 3T Aggregations
    3 Topics | 1 Quiz
    Exercise 1: Creating a view based on an aggregation query
    Exercise 2: Exporting a collection as a .csv file for use by a third-party tool
    Exercise 3: Visualizing collection data in MongoDB Charts
    Reporting with Studio 3T Aggregations: Test your skills
    Course Extras
    Return to MongoDB 301: Aggregation
  • Studio 3T

    MongoDB Enterprise Certified Technology PartnerSince 2014, 3T has been helping thousands of MongoDB developers and administrators with their everyday jobs by providing the finest MongoDB tools on the market. We guarantee the best compatibility with current and legacy releases of MongoDB, continue to deliver new features with every new software release, and provide high quality support.

    Find us on FacebookFind us on TwitterFind us on YouTubeFind us on LinkedIn

    Education

    • Free MongoDB Tutorials
    • Connect to MongoDB
    • Connect to MongoDB Atlas
    • Import Data to MongoDB
    • Export MongoDB Data
    • Build Aggregation Queries
    • Query MongoDB with SQL
    • Migrate from SQL to MongoDB

    Resources

    • Feedback and Support
    • Sales Support
    • Knowledge Base
    • FAQ
    • Reports
    • White Papers
    • Testimonials
    • Discounts

    Company

    • About Us
    • Blog
    • Careers
    • Legal
    • Press
    • Privacy Policy
    • EULA

    © 2023 3T Software Labs Ltd. All rights reserved.

    • Privacy Policy
    • Cookie settings
    • Impressum

    We value your privacy

    With your consent, we and third-party providers use cookies and similar technologies on our website to analyse your use of our site for market research or advertising purposes ("analytics and marketing") and to provide you with additional functions (“functional”). This may result in the creation of pseudonymous usage profiles and the transfer of personal data to third countries, including the USA, which may have no adequate level of protection for the processing of personal data.

    By clicking “Accept all”, you consent to the storage of cookies and the processing of personal data for these purposes, including any transfers to third countries. By clicking on “Decline all”, you do not give your consent and we will only store cookies that are necessary for our website. You can customize the cookies we store on your device or change your selection at any time - thus also revoking your consent with effect for the future - under “Manage Cookies”, or “Cookie Settings” at the bottom of the page. You can find further information in our Privacy Policy.
    Accept all
    Decline all
    Manage cookies
    ✕

    Privacy Preference Center

    With your consent, we and third-party providers use cookies and similar technologies on our website to analyse your use of our site for market research or advertising purposes ("analytics and marketing") and to provide you with additional functions (“functional”). This may result in the creation of pseudonymous usage profiles and the transfer of personal data to third countries, including the USA, which may have no adequate level of protection for the processing of personal data. Please choose for which purposes you wish to give us your consent and store your preferences by clicking on “Accept selected”. You can find further information in our Privacy Policy.

    Accept all cookies

    Manage consent preferences

    Essential cookies are strictly necessary to provide an online service such as our website or a service on our website which you have requested. The website or service will not work without them.

    Performance cookies allow us to collect information such as number of visits and sources of traffic. This information is used in aggregate form to help us understand how our websites are being used, allowing us to improve both our website’s performance and your experience.

    Google Analytics

    Google Ads

    Bing Ads

    Facebook

    LinkedIn

    Quora

    Hotjar

    Reddit

    Functional cookies collect information about your preferences and choices and make using the website a lot easier and more relevant. Without these cookies, some of the site functionality may not work as intended.

    HubSpot

    Social media cookies are cookies used to share user behaviour information with a third-party social media platform. They may consequently effect how social media sites present you with information in the future.

    Accept selected