Connect Mongodb Atlas with Node.js App

2 min read

what is mongodb atlas

MongoDB Atlas is a fully managed cloud database service designed to simplify the deployment and management of MongoDB, a NoSQL database. Unlike traditional relational databases, MongoDB stores data in JSON-like documents, making it highly flexible and scalable for modern applications.

how to connect it with node.js app

  1. new project

  1. name your project and then click next

  1. create project

  1. in create a cluster page click create

  1. in deploy your cluster page i choose free, name your cluster, then click create deployment

  1. copy password and paste it on your notes and click create database user. after that click create a connection method

  1. click drivers

  1. copy connection string to your notes and click done

  1. go to network access and click add ip address

  1. click allow access from anywhere and then click confirm

  1. now your database cluster can be accessed from everywhere

  1. add your connection string that you copied earlier and add it to your .env . also just before the “?” symbol in the connection string, you can place your database name there. here for the example my database name was “notes_db“. don’t forget to add your .env to the .gitignore

  1. install mongoose with npm install mongoose and here’s some code how to connect the database with your node.js app

You're all set!

now your node.js app are connected with mongodb atlas database. next that you need to do is create your models and continue to add more feature to your app.