Node.js : Day 12

Install and Setting up mongoDB cloud using compass

Rahul Kumar
4 min readDec 31, 2024

Install mongodb and setting up for the Project:

To set up MongoDB for your Node.js project, you can either install MongoDB locally on your machine or use MongoDB Atlas, which is MongoDB’s cloud service. Here, I’ll guide you through both approaches, focusing on MongoDB Atlas as it’s a more scalable and managed solution.

Option 1: Setting Up MongoDB Locally

If you want to install MongoDB on your local machine:

Step 1: Download and Install MongoDB

  1. Download MongoDB:

Install MongoDB:

  • For Windows: Run the downloaded installer .msi file and follow the installation steps.

Step 2: Start MongoDB

Once MongoDB is installed:

  • On Windows, MongoDB is typically set to run as a service. You can start the service using:
$ mongod

MongoDB should now be running locally on your system, usually on port 27017.

Step 3: Connect to MongoDB

You can connect to your MongoDB server using the Mongo shell or a MongoDB client:

Open a new terminal window and type:

  • mongo

This should connect you to your local MongoDB instance.

Setting up MongoDB Cloud Using Compass For your project:

Step 1.

Step 2. After Sign in, you will land on this page

  • Just select Free M0, provider, region, and Name as per your preferences,
  • As you can see, I chose AWS as a provider, Mumbai as a Region, and Cluser0 as the Name.

Then click on Create. after that select username and password, Fill username and password of your choice.

then click on Create User.

Inside My local environment, I am just adding entries to your IP access list 0.0.0.0/0 as IP and everywhere as description, So my database is accessible from everywhere.

In last, just click on Finish and close. you will get a pop-up like this.

Step 3.

Inside project0, you would see the Database Deployments as Cluster0.

Now, you can click on connect and you will get a screen like below. In my case, I am selecting Compass to connect with the database.

If you don’t have MongoDB compass, then download it by clicking there.

Copy the connection String and Open MongoDB compass,

Open the compass and paste that connection string with the replaced username and password then connect.

You can see in the below image, that it’s connected.

Congrats, You connected to MongoDB with the MongoDB compass.

Thanks…

--

--

Rahul Kumar
Rahul Kumar

Written by Rahul Kumar

MERN Stack Developer building scalable web apps with MongoDB, Express.js, React.js, Node and TS. Sharing insights and best practices for modern web development.

No responses yet