Atlas allows you to quickly get a MongoDB database running in the cloud, handles all the security and headache-inducing aspects of managing a database, facilitates any future scaling that's needed, and has a generous free-tier for developers who are just getting started.
The key benefits to using a cloud database service like Atlas:
- Scalable from the very beginning.
- Designed specifically for being reliable and maintaining high performance.
- Accessible from anywhere.
- Security controls and features right out of the box.
Let's get started!
First, you'll need to log into the Atlas website or signup for a free account if you haven't already.
After you've successfully logged in or signed up, navigate to the create a cluster page if they didn't already redirect you there. The page should look similar to the image below.
To begin with, choose the free cluster option. This will give you plenty of horsepower to start with.
This will redirect you to a page where you can choose some configuration settings for the server your database will run on.
The first option is the cloud provider and region, which is the location of the server housing your database. Choose the option that is in the closest geographic proximity to where your visitors will be physically located. The closer a request is to the server, the faster it'll be fulfilled.
In the next section, you can choose from a set of cluster tiers with different storage and bandwidth capabilities. Ensure the free option is selected before proceeding.
After that, you can skip the "Additional Settings" section.
Last, give your cluster a name that will be displayed in your account control panel.
When you've gone through each section, hit the "Create Cluster" button to initiate the creation of your new database.
It will take a few minutes for Atlas to create the cluster in their system. When the process finishes, you should see your new database cluster on a page that looks like below.
Before you can use the new database for anything, you'll need to first secure it by adding your IP address to the connection whitelist and then create a MongoDB username and password for the database.
Click on the "Connect" button in the cluster dashboard area. This will open a dialog box that will guide you through configuring some security settings for the database.
First, click on the "Add Your Current IP Address" button and verify that Atlas has populated the input field with the correct IP address matching your local development machine.
If it's correct, click the "Add IP Address" button to add your IP address to the whitelist. This will allow you to successfully connect to the database.
In the bottom section labeled "Create a MongoDB User", enter a username and password for a new MongoDB database user. These are the credentials you'll use to read and write data to and from the database.
When you've added a username and password, click on the "Create MongoDB User" button to generate the new user.
With both the "Whitelist a connection IP address" and "Create a MongoDB User" sections complete, you can click the "Choose a connection method" button to move on to the next step.
There are three different ways to connect to your new database, including the Mongo Shell, using a MongoDB native driver alongside your favorite programming language, and using MongoDB's GUI called Compass.
If you wanted to connect to your database using the Node.js programming language, you would want to select the "Connect your application" option. When you click on that option, a page will be displayed where Atlas generates a connection string you can copy and paste into your application.
You'd also make sure Node.js is selected as the coding language driver. In the second section, a connection string should be generated for you.
Then, you would copy that string to your clipboard and use it in your coding project.
There you go! Now you have a new MongoDB database created in the cloud using Atlas.
Thanks for reading and happy coding!