EventGet 50% off your ticket to MongoDB.local NYC on May 2. Use code Web50!Learn more >>
MongoDB Developer
MongoDB
plus
Sign in to follow topics
MongoDB Developer Centerchevron-right
Developer Topicschevron-right
Productschevron-right
MongoDBchevron-right

5 Different Ways to Deploy a Free Database with MongoDB Atlas

Nic Raboy5 min read • Published Dec 17, 2021 • Updated Feb 03, 2023
MongoDBCLI
Facebook Icontwitter iconlinkedin icon
Rate this quickstart
star-empty
star-empty
star-empty
star-empty
star-empty
You might have already known that MongoDB offers a free tier 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.

Using the Atlas Web UI to Deploy a Cluster

If you're a fan of point and click deployments like I am, the web UI for MongoDB Atlas will probably fit your needs. Let's take a quick look at how to deploy a new cluster with a database using the UI found within the MongoDB Cloud Dashboard.
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.
Create a New MongoDB Atlas Cluster on the Web
Create a New MongoDB Atlas Cluster on the Web
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.
MongoDB Atlas Cloud Service Provider
MongoDB Atlas Cloud Service Provider
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.
Cluster Dashboard in MongoDB Atlas
Cluster Dashboard in MongoDB Atlas
At this point, you can continue exploring Atlas, create a database or two, and be on your way to creating great applications. A good next step after deploying your cluster would be adding entries to your access list. You can learn how to do that here.
Let's say you prefer a more CLI-driven approach.

Using the MongoDB CLI to Deploy a Cluster

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.
To install the MongoDB CLI, check out the installation documentation and follow the instructions. You'll also need to have a MongoDB Cloud account created.
If this is your first time using the MongoDB CLI, check out the configuration documentation to learn how to add your credentials and other information.
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.
To see some of the other options for the CLI, check out the documentation.

Using the Atlas Admin API to Deploy a Cluster

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 documentation. You can try the above example after switching the GROUP_ID, PUBLIC_KEY, and PRIVATE_KEY placeholders with those found in your Atlas dashboard. The GROUP_ID is the project id representing where you'd like to create your cluster. The PUBLIC_KEY and PRIVATE_KEY are the keys for a particular project with proper permissions for creating clusters.
The same cURL components can be executed in a programming language or even a tool like Postman. The Atlas Admin API is not limited to just cURL using a command line.
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.
For information on the other optional fields that can be used in the request, refer to the documentation.

Using HashiCorp Terraform to Deploy a Cluster

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:
The configuration used in this example was taken from the Terraform template accessible within the Visual Studio Code Extension for MongoDB. However, if you'd like to learn more about Terraform with MongoDB, check out the official provider information within the Terraform Registry.

Using AWS CloudFormation to Deploy a Cluster

If your applications are all hosted in AWS, then CloudFormation, another IaC solution, may be one you want to utilize.
If you're interested in a script-like configuration for CloudFormation, Cloud Product Manager Jason Mimick wrote a thorough tutorial titled Get Started with MongoDB Atlas and AWS CloudFormation. However, like I mentioned earlier, I'm a fan of a point and click solution.
A point and click solution can be accomplished with AWS CloudFormation! Navigate to the MongoDB Atlas on AWS page and click "How to Deploy."
You'll have a few options, but the simplest option is to launch the Quick Start for deploying without VPC peering.
MongoDB Atlas with AWS CloudFormation Quick Start
MongoDB Atlas with AWS CloudFormation Quick Start
The next steps involve following a four-part configuration and deployment wizard.
The first step consists of selecting a configuration template.
MongoDB Atlas with AWS CloudFormation Quick Start
MongoDB Atlas with AWS CloudFormation Quick Start
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.
MongoDB Atlas with AWS CloudFormation Quick Start
MongoDB Atlas with AWS CloudFormation Quick Start
Replace the fields with your own information, including the public key, private key, and organization id to be used with CloudFormation. Once more, these values can be found and configured within your MongoDB Atlas Dashboard.
MongoDB Atlas with AWS CloudFormation Quick Start
MongoDB Atlas with AWS CloudFormation Quick Start
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.

Conclusion

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.
If you get stuck with your MongoDB Atlas deployment, navigate to the MongoDB Community Forums for some help!

Facebook Icontwitter iconlinkedin icon
Rate this quickstart
star-empty
star-empty
star-empty
star-empty
star-empty
Related
Quickstart

MongoDB and Node.js Tutorial - CRUD Operations


Aug 22, 2023 | 17 min read
Tutorial

Update Array Elements in a Document with MQL Positional Operators


Feb 03, 2023 | 6 min read
Article

Using MongoDB Change Streams in Java


Apr 04, 2023 | 6 min read
Tutorial

Introduction to LangChain and MongoDB Atlas Vector Search


Jan 12, 2024 | 5 min read
Table of Contents