Hi! So you want to get with the multiple, or singular, database joys of Compose. For this walkthrough we'll be setting up a MongoDB database so grab your keyboard controller and mouse and press ⓧ to continue.
So where do we start
You find yourself on the front page of Compose. You start by getting yourself a Compose account and that begins with clicking the "Free 30 day trial" button at the top of the page. You'll now see a form that looks like this:
We'll trust you can remember your name, company, email and can come up with a password. Pro-tip: the company/account name is used to create your Compose account name, so if you have a company name, use that, if you are creating a personal account, pick something cool. No, cooler than that. No, a little less cool, there, Yes, perfect. We won't be referring to it again here, but when you need to use it, you'll appreciate it.
There's also the other column where you can select what database you want to setup. MongoDB is top of our list because it was on Compose first and it's selected by default. Notice how it says $18 a month per gigabyte. Well, when you sign up, you get 30 days free trial which should be enough time to see if you want to make your data at home at Compose.
Next, you need to enter your payment details. This credit card information is handled by Stripe and the Remember Me checkbox lets you sign up with Stripe for faster payments elsewhere. We don't start the billing clock till you've had your first 30 days free.
With payment details in and accepted, the Compose system swings into action creating your first MongoDB deployment. You'll be able to see the progress as you are redirected to the "Jobs" display:
Ok, I'm all signed up and what's a deployment?
A deployment is a cluster of systems running MongoDB for you. It's not your database, but it's what hosts your database. Actually, with MongoDB on Compose, your deployment can host as many databases as you need and they'll all share the same pool of resources.
Right now though, we only need one database and we have to create it. Click on the "Databases" tab on the sidebar. You'll see a list of databases, or you would if there were any. Instead you are invited to create a database.
Enter a database name and click on the Create Database button...
Now you have a MongoDB database and it's almost ready to use...
Actually, you can use it by creating a collection here and using the Compose data browser to create documents in that collection. But if you want to access your database from outside the Compose Dashboard you'll need to create some users.
But I already have a user!
Yes, but what you've got is an account which you can log in to with your email address and password for the Compose Dashboard and your own Compose account. Those credentials are only ever used to log into the Compose Dashboard.
So what about the databases?
It varies from database technology to database technology. You see, by design, Compose databases have no idea those Compose credentials exist. We try to avoid making modifications to the database's code. Instead, we make it as easy as possible to create new users for each database.
The important thing is not to fall into the hole some people get into of trying to use your Dashboard account credentials to log in your database-using application's connections. What you need to do is to create a database-specific user.
For our MongoDB, if we look at the sidebar for our newly created database we can see an entry for Users. Click on that...
Then click on Add User...
Here you can create a user and give them a password. There are also options to make the new user read-only or have oplog-access, but we'll skip those buttons for now as we want to make a normal user. Just enter a username and a password and click "Add User". Now your MongoDB database has a user.
So what do I connect to?
Ah yes, you'll be wanting the connection details for your database too. Click on Admin in the sidebar and you'll see something like this:
At the top are the Connection Strings. The first one is the Replica Set URI. If you have a sufficiently modern MongoDB driver you can use just this string to connect to your MongoDB database. After, of course, substituting in your selected username and password. This is your "full service" URI; everything is specified in here - both servers in the replica set, primary and secondary, the name of the database and the name of the replica set.
If you have less modern drivers or applications then they may only use a single hostname, a port and a database name because they don't know about replica sets. You can extract that information from the Replica Set URI or you can look down to the Mongo Console command beneath it. It uses a simplified address for the database because it can only talk to a single server at a time. Here you can see the hostname, a colon, the port number and the database name. This will allow you to connect but you should be thinking about updating your drivers so you can work with the Compose MongoDB replica set. Once you've done that your application will be resilient to any configuration changes.
If you want to run the Mongo Console you'll need the
mongo command, and that means you'll have to install MongoDB locally. You can download MongoDB for your system from Mongodb.org or see if it's available in your operating system's package management – On Mac OS X, install Homebrew and then run
brew install mongo. It is worth getting the Mongo console though as you can then use the mongo shell, a powerful command line way to talking to the database.
As for connecting your application, consult the Compose Language guides which will give examples of 8 different ways to plug applications into your new Compose database.
The final step? Have fun with Compose MongoDB and if you have a problem, drop a line to support or file a ticket for assistance.