How to Create a MongoDB Cluster in MongoDB Atlas

MongoDB Atlas is a fully managed cloud database service built and maintained by the same team behind MongoDB. In this lesson, we'll create our first MongoDB cluster with MongoDB Atlas.

Project Source Code

Get the project source code below, and follow along with the lesson material.

Download Project Source Code

To set up the project on your local machine, please follow the directions provided in the README.md file. If you run into any issues with running the project source code, then feel free to reach out to the author in the course's Discord channel.

This lesson preview is part of the TinyHouse: A Fullstack React Masterclass with TypeScript and GraphQL course and can be unlocked immediately with a \newline Pro subscription or a single-time purchase. Already have access to this course? Log in here.

This video is available to students only
Unlock This Course

Get unlimited access to TinyHouse: A Fullstack React Masterclass with TypeScript and GraphQL, plus 70+ \newline books, guides and courses with the \newline Pro subscription.

Thumbnail for the \newline course TinyHouse: A Fullstack React Masterclass with TypeScript and GraphQL

Just like how we intend to deploy our server to the cloud, we're going to implement our database on the cloud as well. This is important because the moment our servers in the cloud during production , it needs to access a database on the cloud as well. We can't just have a database on our static local computer. In this lesson, we're going to set up a Mongo cluster with MongoDB Atlas, which is a fully managed cloud database built and maintained by the same team behind MongoDB. Now, a cluster is essentially a group of two or more servers that work together to provide users with higher availability, scalability, and reliability. To use Mongo's cloud service, Mongo Atlas, the first thing that needs to be done is to have an account created. We're going to go through the account creation process here again, just to show you the steps that are needed to be done to create an account, and finally create a new cluster. We'll go to the login, register page. Now, as a side note, we're going to provide this link and all the other additional links that might be needed in the lesson documentation. In the register page, this is where we can fill our information to create a brand new account. Once we've submitted the form and created our account, we will be redirected and prompted to create our very first cluster. Here's where MongoDB Atlas recommends a lot of their popular options, but it do give us the capability of customizing how our cluster is set up the way we see fit. The first thing that they actually recommend or discuss is the cloud provider and region for where our cluster is going to be. In terms of cloud providers, they offer AWS, Google Cloud Platform, Azure, and in terms of regions, there's North America, Europe, and even Asia. Now, there is some differences in terms of using a free tier or not. We're going to stick with a free tier, and they also recommend so, and we advise you to only think about upgrading to a production level cluster, only when you're ready to actually move to a production level app. But for the other than that, we're going to keep things very simple. We're not actually going to change any of the settings they provide, and we're simply going to just create our cluster as is. In terms of region, it's going to be kept in North Virginia, US East One. Note that it takes about seven to ten minutes to create and provision a new cluster. So to actually continue, we'll have to wait just a few minutes until a cluster is going to be created. Once ready, your cluster is being created, the message will no longer be seen, and we'll actually see some information about our cluster. Notice that Atlas actually creates our cluster within a particular project. Atlas allows us to create a hierarchy of organizations and projects to manage many different clusters if we may have them, but in this case, we already have a project created for us, and we have a cluster now created within our project. There's a few things we're now going to do to get started, the first being creating a new database user. On the left-hand side panel, we'll click the database access button in the security section, and then we're going to click add new user. This new user will have read and write access to the database cluster, so we'll fill in the user information, and then finally we're going to add this new user. The next thing we're going to do is we're going to whitelist an IP address. We'll head to the network access section under security of the side nav panel, and then we'll click add IP address. Here we have the option to choose which IP addresses can have access to our database. To keep things simple, and since we're going to host our server to the cloud, which doesn't really have a predetermined IP address, we'll simply click allow access from anywhere. Next, we're going to add some sample data into our cluster. We'll go back to the clusters dashboard, where we're actually able to see information about our cluster, and we'll click collections. Here we'll then click add my own data, and we'll provide a name for our database. We'll call it main to reference it as the main database, and then we'll give a name to our collection, with which we can say test_list ings to reference it as the sample test collection. One thing that we really like about MongoDB Atlas is their really intuitive UI to be able to sort of navigate and see the data within a database and collections. In this case, we're actually able to see information within the main database we've created and the test_listings collection, as specified on the right-hand side as main. test_listings. At this moment, we don't have any data, but if we did, we'd also be able to sort of find and query information right in our UI right here. With that said, let's actually add some new data. We'll click the insert document button on the top right corner, and in this case, we're able to insert a new document into our collection. We'll keep it simple, and we're going to add two new fields here, just title and address, that denotes a simple document that represents a single listing. You're more than welcome to add what you like, but we're going to fill this in with some mock data of our own. Notice that as we're inserting fields here, we're actually able to insert the type of field you want. That Mongo actually recognize things like null integer, 64-bit integer, 32-bit integer, code, boolean, binary, arrays, etc. But in our case, the two fields we're going to add are just going to be strings . The object ID field is unique because every single document within a collection has a unique identifier, and this is the unique identifier that MongoDB Atlas has already prepared for us. Once inserted, we're able to see in the UI the documents we've just added. With sample data available in our cluster, the only thing left for us to do is to connect our server application with our MongoDB Atlas cluster. When we head over to the overview tab here, there's a connect button, which provides a series of different methods and options to actually make a connection. We're going to pick this up in the next lesson once we start to discuss how we 're going to make the connection from the server side. [BLANK_AUDIO]