5 Different Ways to Deploy a Free Database with MongoDB Atlas
Rate this quickstart
You might have already known that MongoDB offers a through M0 clusters on MongoDB Atlas, but did you know that there are numerous ways to deploy depending on your infrastructure needs? To be clear, there's no wrong way to deploy a MongoDB Atlas cluster, but there could be an easier way to fit your operations needs.
In this article, we're going to have a quick look at the various ways you can deploy a MongoDB Atlas cluster using tools like Terraform, CloudFormation, CLIs, and simple point and click.
Within the Databases tab for your account, if you don't have any databases or clusters, you'll be presented with the opportunity to build one using the "Build a Database" button.
Since we're keeping things free for this article, let's choose the "Shared" option when presented on the next screen. If you think you'll need something else, don't let me stop you!
After selecting "Shared" from the options, you'll be able to create a new cluster by first selecting your cloud service provider and region.
You can use the defaults, or select a provider or region that you would prefer to use. Your choice has no impact on how you will end up working with your cluster. However, choosing a provider and location that matches your other services could render performance improvements.
After selecting the "Create Cluster" button, your cluster will deploy. This could take a few minutes depending on your cluster size.
Let's say you prefer a more CLI-driven approach.
The MongoDB CLI can be useful if you want to do script-based deployments or if you prefer to do everything from the command line.
For this example, we're going to use the quick start functionality that the CLI offers. From the CLI, execute the following:
Using the quick start approach, you'll be presented with a series of questions regarding how you want your Atlas cluster configured. This includes the creation of users, network access rules, and other various pieces of information.
A similar option to using the CLI for creating MongoDB Atlas clusters is to use the Atlas Admin API. One difference here is that you don't need to download or install any particular CLI and you can instead use HTTP requests to get the job done using anything capable of making HTTP requests.
Take the following HTTP request, for example, one that can still be executed from the command prompt:
The above cURL request is a trimmed version, containing just the required parameters, taken from the Atlas Admin API . You can try the above example after switching the
PRIVATE_KEYplaceholders with those found in your Atlas dashboard. The
GROUP_IDis the project id representing where you'd like to create your cluster. The
PRIVATE_KEYare the keys for a particular project with proper permissions for creating clusters.
While you can use the Atlas Admin API to create users, apply access rules, and similar, it would take a few different HTTP requests in comparison to what we saw with the CLI because the CLI was designed to make these kinds of interactions a little easier.
There's a chance that your organization is already using an infrastructure-as-code (IaC) solution such as Terraform. The great news is that we have a Terraform provider for MongoDB Atlas that allows you to create a free Atlas database easily.
Take the following example Terraform configuration:
If you added the above configuration to a main.tf file and swapped out the information at the top of the file with your own, you could execute the following commands to deploy a cluster with Terraform:
If your applications are all hosted in AWS, then CloudFormation, another IaC solution, may be one you want to utilize.
The next steps involve following a four-part configuration and deployment wizard.
The first step consists of selecting a configuration template.
Unless you know your way around CloudFormation, the defaults should work fine.
The second step of the configuration wizard is for defining the configuration information for MongoDB Atlas. This is what was seen in other parts of this article.
The final stage of the configuration wizard is for defining permissions. For the sake of this article, everything in the final stage will be left with the default provided information, but feel free to use your own.
Once you review the CloudFormation configuration, you can proceed to the deployment, which could take a few minutes.
As I mentioned, if you'd prefer not to go through this wizard, you can also explore a more scripted approach using the CloudFormation and AWS CLI.
You just got an introduction to some of the ways that you can deploy MongoDB Atlas clusters. Like I mentioned earlier, there isn't a wrong way, but there could be a better way depending on how you're already managing your infrastructure.