Navigation
This documentation refers to the on premises version of MongoDB Charts. For documentation on the MongoDB Charts SaaS application in Atlas, click here.

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.

Note

Before completing this procedure, ensure that you have allowed your Atlas cluster to accept connections from MongoDB Charts.

  1. Click the Data Sources tab.

  2. Click New Data Source.

  3. In the New Data Source dialog, enter the connection string which points to the cluster containing the imported data.

    Example

    The following connection string points to an Atlas cluster called jefftestcluster and authenticates a user named admin on the admin database.

    mongodb://admin:<password>@jefftestcluster-shard-00-00-bfkni.mongodb.net:27017,jefftestcluster-shard-00-01-bfkni.mongodb.net:27017,jefftestcluster-shard-00-02-bfkni.mongodb.net:27017/test?ssl=true&replicaSet=JeffTestCluster-shard-0&authSource=admin
    

    For further instructions on determining your Atlas connection string, see the Connect Your Application Atlas documentation.

  4. Click Connect.

  5. Select the test.supplySales collection.

  6. Click Set Permissions.

  7. Select the Open Access option.

  8. Click Publish Data Source.

Next Steps

Now that you have established the data source in Charts, you can now Create a New Dashboard which will hold the visualizations.