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

Estimated Time to Complete: 10 minutes

Prerequisites

The following items are required to complete this tutorial:

Download the Data

Download the example dataset from https://raw.githubusercontent.com/steveren/docs-assets/charts-tutorial/movieDetails.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.movieDetails collection of your Atlas cluster in the following step.

The movieDetails.json file is 1.4 MB and contains records for 2295 movies. The following is a sample document from the dataset:

{
     "_id" : ObjectId("5b107bec1d2952d0da904dd7"),
     "title" : "Titan A.E.",
     "year" : 2000,
     "rated" : "PG",
     "runtime" : 94,
     "countries" : [
             "USA"
     ],
     "genres" : [
             "Animation",
             "Action",
             "Adventure"
     ],
     "director" : "Don Bluth, Gary Goldman, Art Vitello",
     "writers" : [
             "Hans Bauer",
             "Randall McCormick",
             "Ben Edlund",
             "John August",
             "Joss Whedon"
     ],
     "actors" : [
             "Matt Damon",
             "Bill Pullman",
             "John Leguizamo",
             "Nathan Lane"
     ],
     "plot" : "A young man learns that he has to find a hidden Earth ship before an enemy alien species does in order to secure the survival of humanity.",
     "poster" : "http://ia.media-imdb.com/images/M/MV5BMjE0NTU0ODg4NV5BMl5BanBnXkFtZTcwNzY3MTQyMQ@@._V1_SX300.jpg",
     "imdb" : {
             "id" : "tt0120913",
             "rating" : 6.6,
             "votes" : 50875
     },
     "tomato" : {
             "meter" : 52,
             "image" : "rotten",
             "rating" : 5.7,
             "reviews" : 99,
             "fresh" : 51,
             "consensus" : "Great visuals, but the story feels like a cut-and-paste job of other sci-fi movies.",
             "userMeter" : 60,
             "userRating" : 3.2,
             "userReviews" : 69055
     },
     "metacritic" : 48,
     "awards" : {
             "wins" : 1,
             "nominations" : 7,
             "text" : "1 win & 7 nominations."
     },
     "type" : "movie"
}

Import the Data

Before you can use your dataset with Charts, you need to add it to a MongoDB collection. Use mongoimport to import the contents of that file into the test.movieDetails collection on your Atlas cluster.

mongoimport --host <atlasHostname> --ssl -u <username> -p <password> --authenticationDatabase admin \
--db test --collection movieDetails \
--drop --file <path/to/movieDetails.json>

Note

Refer to mongoimport for more information on using the import tool to add data to a MongoDB collection.

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.movieDetails collection.

  6. Click Set Permissions.

    Leave the permissions as the default Private option. For more information on user permissions in Charts, see permissions.

  7. Click Publish Data Source.

You’re now ready to create a dashboard and start adding charts to it.

Next Steps

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