Getting Started with MongoDB Atlas: A Step-by-Step Guide

MongoDB Atlas is a cloud-based database service that provides a fully managed instance of the MongoDB database. It is a platform-as-a-service (PaaS) offering from MongoDB, Inc. that allows you to deploy, manage, and scale your MongoDB deployments with ease.

Step 1:

Go to MongoDB official website: Click here

mongodb atlas

Step 2:

Click on Try free and create a new Atlas account or sign up with google

Step 3:

Once you have a MongoDB Atlas account, you will need to create a new MongoDB Atlas cluster.

shared

Click on Create Cluster

Step 4:

Create Database User with Name and Password

You need to create a database user to be able to use this service. It will be used to allow access to the particular mongo cluster that you have just created. Click on Database Access under Security in the left sidebar and enter the user name and password.

quickstart

Enter 0.0.0.0/0 as whitelist entry and click Add Entry. This will allow users to use our mongo atlas cluster from any IP address. Once done, click on Finish and Close.

ip address

Step 5:

Now its time to finally get the connection URI string that will allow our application to use mongo atlas as a database service in the cloud. Click on Clusters on the left sidebar and then click Connect.

connect

Copy the below connection string and to to your project and create a file with the name .env in the root of the project and paste connection string that you just copied

uri
env

Note: Replace <password> with the password and the <username> with the username

Step 6:

Test the connection

testing
const mongoose = require('mongoose');

module.exports = async () => {
    const mongoUri = process.env.DATABASE;
    try{
        mongoose.connect(mongoUri, { useNewUrlParser: true, useUnifiedTopology: true }, () => {
            console.log('mongodb connection established')
        });
    }catch(e){
        console.log(e);
        process.exit(1);
    }
};
connection established

MongoDB connection successfully established

MongoDB Atlas CLI

The MongoDB Atlas CLI (Command Line Interface) is a command-line tool that allows you to manage your MongoDB Atlas deployments from your local machine. It provides a range of powerful features that simplify the process of managing your Atlas clusters, including the ability to create, configure, and manage clusters, databases, and collections, as well as to perform backups and restores.

To install Atlas CLI: Click here

Once you installed the CLI, you will need to authenticate with your MongoDB Atlas account then you can use the CLI to manage your MongoDB Atlas deployments from your local machine.

In conclusion, MongoDB is a powerful and flexible NoSQL database that is widely used by developers and organizations around the world. With its document-oriented data model and powerful query language, MongoDB makes it easy to store and manage large volumes of unstructured data, making it an ideal choice for modern, data-driven applications.

Leave a Reply

Your email address will not be published. Required fields are marked *