Compose Database-as-a-Service Help and Documentation

Everything you need to know about Compose, Hosted or Enterprise, is here in our help system. Whether you run one database for your businesses' sole application or six different databases to support an entire corporation, we've got the information you need.

MongoDB Classic Playground

Welcome to the MongoDB Playground. The purpose of this document is to gracefully ease the uninitiated into their first live, tinker-able MongoDB database deployment. You'll use Compose to deploy, then populate a local DB instance to show you some simple command line work that will get sample data into your deployment, for your querying pleasure.

The best way to familiarize yourself with a database is to jump in. If you muck something up beyond repair, you can easily destroy your deployment and start a new one. Just as a bee needs flowers, your database is going to need a dataset.

The sample data set provided by MongoDB gives us a lengthy clump of data to play with: 11.9MB, great for sample purposes. Right click, save-as, and remember which directory you saved it to. We'll need to know the directory later once we import our data.

Once the data is in the database, we'll be able to tell how many documents we have, run queries, and access it via our applications.

      "coord":[-73.96805719999999, 40.7925587],
      "street":"Columbus Avenue",
   "cuisine":"American ",
   "name":"P & S Deli Grocery",

We have some tasty data here! Above, we have what MongoDB refers to as a "document" of data - MongoDB is a document style, NoSQL database. This set of restaurant "documents" will live in our collection, which we've titled 'Restaurants'.

MongoDB likes its data to be in BSON format. BSON is similar to JSON, with some added awareness. The JSON format and its derivatives have some advantages: readability and simplicity. Without any prior database knowledge, you can look at a well-formatted JSON-type document (like our example) and understand what you're seeing. BSON adds support for additional data type formats to improve encoding/decoding between various languages.

We have a stack of restaurant data: locations, names, reviews - let's get it into MongoDB and see what we can do with this.

Creating A Playground

Login to your compose account. Don't have one? Sign-up here.

For our initial run through, we'll be using a MongoDB+ deployment. While we're just experimenting, if your experiments progress into a fully functional application, it will scale as you require it to.

You can get there by selecting 'New Deployment', clicking MongoDB+, then clicking the 'Create Deployment' button. Alternatively, if you're logged in already, simply click here.

You now have your first MongoDB database!

MongoDB, On Your Local Machine

You'll need a way to connect to your new instance. If you're on an a Mac or Linux workstation, you'll have access to a command line. You'll need that to both install, and connect to, your database.


brew install mongodb

On Linux:

sudo apt-get install mongodb

That wasn't bad.

Connecting to MongoDB

Our MongoDB instance is easy to connect to, but it will require you to meet it halfway.

Within your deployment in the Compose app, head to the 'Users' menu and select 'Add User'. Provide a username and a password.

You've now provided Compose with three relevant variables that will allow you to connect to your database:

1) The name of the database.
2) The user's name.
3) The user's password.

Click 'Admin' within the app, here you'll find your connection string:

At the moment, we want the string for the 'Mongo Console':

mongo -u <user> -p<password>

For your string, you'll see the name you provided your database instead of 'MongoDBPlayground'. Of course, provide your actual username and password.

Now on your local workstation, let's connect to it:

$ mongo -u <user> -p<password>
MongoDB shell version: 2.4.9
connecting to:

If you see a > eagerly awaiting your input, you've connect - great!

For now, let's get out of here. Hit ctrl+C to close out of your session.

Importing Our Dataset

We built a sandbox and we confirmed we can connect to it, now let's use this database for what it was made for: holding data.

Make sure you are in the directory where we saved our dataset, and run this command to put the set into our database.

$ mongoimport --host --port 10045 -u zoolander -pbluesteel --db MongoDBPlayground --collection restaurants --file dataset.json

We use 'mongoimport' to bring the dataset into the database. There are a variety of attributes here, let's break them down so we don't get into the habit of plunking things into our terminal that we aren't sure of:

  • --host: Specify the hostname of your database instance. When we connected above, we use our hostname of

  • --port: The port associated with our hostname. In our example case, 10045.

  • -u & -p: The username and password that we've added within the 'users' section of our database.

  • --collection: The name we want to provide our "collection" of documents that we are entering into the database.

  • --file: The name of the file we're importing. If you just saved the dataset above as is, you too will have the name dataset.json. Make sure you are running this command in the directory where the file is located.

You'll see the dataset upload, once it's finished, click on 'Collections' within the Compose application.

Let's take a step back. We've managed to set-up a properly specced, secure, scaleable database by deploying a MongoDB sandbox and running a single command line operation.

Powerful stuff. Now, let's explore. Click on restaurants. You will see your data are query-able, organized, formatted, and ready for you to analyze or connect to an application.

MongoDB Classic Playground