DEV Community

Ricardo
Ricardo

Posted on • Originally published at rmauro.dev on

Create a free MongoDb Cluster in the Cloud - Mongo Atlas free account

MongoDB is a document-oriented NoSQL database used for high volume data storage. Instead of using tables and rows as in the traditional relational databases, MongoDB makes use of collections and documents.

In personal opnion, MongoDb is very easy to get started - I love MongoDb. It's easy to setup, write and read data.

If you are like me - like MongoDb - or you're just studying it. Mongo Atlas is the right choice for you to get started.

Mongo Atlas is like the Cloud for MongoDb database.

Mongo Atlas is Cloud-hosted MongoDB service on AWS, Azure and Google Cloud. Deploy, operate, and scale a MongoDB database in just a few clicks

https://www.mongodb.com/cloud/atlas/lp/try2

Mongo Atlas it is free for developers and SRE like us and easy to get started.

In this tutorial let's lean how to:

  • Configure Mongo Atlas and MongoDb
  • Set application username and password
  • Set Mongo Atlas firewall - grant IP address access to the cluster

Configuring MongoDB in the Mongo Atlas cloud

Let's get started. Navigate to Mongo Atlas website (https://www.mongodb.com/cloud/atlas)

Click Try free button (top right corner) if you don't have an account.

Creating an account to access Mongo Atlas

Fill in the required information requested, such as email, first name, last name and password. Accepted the terms of agreement and them click Get started free - yes, it's free.

Activate your account with the received email (Welcome to MongoDB or something like that).

Sign In

Log in using your credentials (username and password).

Preparing your environment - creating the cluster

Let's use our first cluster.

By the way, cluster is where the MongoDb databases will be stored - we can create more than one.

  1. Click on Build a Cluster.
  2. Select the free (Starter Clusters) cluster and then click Create a cluster.
  3. In Cloud Provider select Azureand leave pre-selected region selected Virginia (eastus2).
  4. Leave the default value for the rest of the fields.
  5. Last click on Create Cluster and wait it to finish.

The blue top bar indicates the status of the creation of the cluster. It may take a while to finish.

Important thing on the dashboard screen - What are we seeing here?

On the left side we have menu with options to manage our cluster, such as Database Access and Network Access.

  • Data Storage/Clusters - contains general information about the cluster. It's also where we will get the ConnectionString for our application to use.
  • Security/Database Access - we can manage users, passwords and permissions to access the databases.
  • Security/Network Access - manage firewall rules - grant or block IP address for accessing our cluster.

These are the main options for us.

Preparing the environment for our application

Let's create our first database so we can start insert and reading data from it.

So far we have only the cluster, with no databases to access.

Creating the first user

Now we should create a database user for our application to use.

Click on menu Security/Database Access and then on ADD NEW USER (right side - green button).

Username = studenty
Password = randompassowrd - or you can use *Autogenerate Secure Password* button
User privileges = read and write to any database
Enter fullscreen mode Exit fullscreen mode
user fields

Add User to create our first user.

Creating our first firewall rule

In this section we're going to create a rule to grant access for our IP address to access the cluster.

Click on menu Security/Network Access and then on ADD IP ADDRESS button.

On the popup window click on ADD CURRENT IP ADDRESS - this will grant access to your current IP address.

Finally click on Confirm button.

Collecting Connection String

The connectionString contains the necessary information for a given application (C#, Python, NodeJs, C, C++, Go, etc) to access our database.

Click on Data Store/Clusters menu and then click on CONNECT.

On opened popup click on Connect your application.

popup mongo atlas
popup mongo atlas

Select the driver language you need and the version and them copy the connection string.

You should get something like:

client = pymongo.MongoClient("mongodb+srv://randuser:<password>@nops.dhfxf.azure.mongodb.net/myFirstDatabase?retryWrites=true&w=majority")
db = client.test
Enter fullscreen mode Exit fullscreen mode

Don't forget to replace the password field with your actual password.

Sumary

In this blog post we saw how to

  • create a Mongo Atlas account
  • create a cluster
  • create a database
  • setup firewall rules
  • setup a user and password

Hope you like it and leave a comment.

Top comments (0)