Skip to content

How to install MongoDB

Aasher Kataria edited this page Nov 17, 2022 · 1 revision

Errors you might run into before setting up MongoDB

When running npm run dev you might notice this error pop-up:

image

This means that you do not have a .env file configured along with MongoDB

This guide will help you set up MongoDB and your environmental variables

Step 1: Create an .env file in your project root

Simply create a new file and name it .env

image

It should automatically be greyed out and not included in any future commits/pushes.

Step 2: Create a shared database cluster using Mongo Atlas

  1. Go to Mongo Atlas and create a new account.

  2. Create a Shared Cluster:

image

  1. Choose AWS, Oregon, (us-west2)

image

  1. Change the cluster name to textbook-marketplace

image

  1. Create a su (super user)

image

  1. Select My Local Environment under Where would you like to connect from?

image

  1. Allow access from anywhere

add the IP address 0.0.0.0/0 to your Access list

image

Step 3: Connect your local environment with your cluster

  1. Click Connect

image

  1. Connect using MongoDB Compass

image

  1. Download MongoDB Compass and paste the server link under a New Connection and hit Connect

image

image

Step 4: Add Mongodb URI to code

  1. Copy the same server address to a new variable in your .env file under the name MONGODB_URI=

  2. Replace with the password you assigned in your cluster for your super user.

image

  1. Run npm run dev, and you will now be connected to your mongodb cluster