Navigation
This documentation refers to the MongoDB Charts beta service in MongoDB Atlas. Read the on-premises documentation to learn how to use the MongoDB Charts beta on site.

Setup and Import the Data

Time to Complete: 8 minutes

Prerequisites

The following items are required to complete this tutorial:

Download the Data

Download the example dataset from https://raw.githubusercontent.com/mongodb/docs-assets/charts-tutorial/mgenerate-order-data.json. To download the documents, right-click on the URL and select Save Link As. This file contains the data you will import into the test.supplySales collection of your Atlas cluster in the following step.

To give an idea of the data you will visualize, here is a sample document from the dataset:

{
  "_id": {"$oid":"5afb2c3dc09c8d2dd5852cf2"},
  "saleDate":{"$date":"2017-11-08T19:06:53.449Z"},
  "items":[
    {
      "name":"envelopes",
      "tags":["stationary","office","general"],
      "price":{"$numberDecimal":"9.83"},
      "quantity":10
    },
    {
      "name":"pens",
      "tags":["office","writing","school","stationary"],
      "price":{"$numberDecimal":"73.62"},
      "quantity":2
    },
    {
      "name":"laptop",
      "tags":["office","school","electronics"],
      "price":{"$numberDecimal":"595.72"},
      "quantity":4
    },
    {
      "name":"notepad",
      "tags":["office","writing","school"],
      "price":{"$numberDecimal":"34.65"},
      "quantity":3
    }
  ],
  "storeLocation":"Seattle",
  "customer":{
    "gender":"M",
    "age":45,
    "email":"uga@we.so",
    "satisfaction":4
  },
  "couponUsed":false,
  "purchaseMethod":"Online"
}

Import the Data

Now that you have a file containing the documents you will be visualizing in Charts, use mongoimport to import the contents of that file into the test.supplySales collection.

mongoimport --host <myAtlasHost> --ssl -u <USER> -p <PASSWORD> --authenticationDatabase admin \
--db test --collection supplySales \
--drop --file <path/to/mgenerate-order-data.json>

Note

Refer to the mongoimport page to familiarize yourself with the proper command syntax.

Additionally, the Atlas documentation for Connecting to a Cluster using Command Line Tools may prove helpful.

Add the Data Collection as a Data Source

Now that the data is in the desired collection, add the collection as a data source in MongoDB Charts. Adding a collection as a data source links the collection to Charts and allows us to create visualizations using that data.

  1. Launch Charts from the Atlas cluster which contains your imported data.

  2. Click the Data Sources tab.

  3. Click New Data Source.

  4. In the New Data Source dialog, select the Atlas Project which contains your imported data.

  5. Click Connect.

  6. Select the test.supplySales collection.

  7. Click Set Permissions.

  8. Leave these options as default and click Publish Data Source.

    Note

    For details on data source permissions, see the Data Source Permissions page.

Next Steps

Now that you have established the data source in Charts, you can Create a New Dashboard which will use this data source to create visualizations.