Sign in
Log inSign up
How to setup MongoDB on Windows and make it run anywhere within the terminal

How to setup MongoDB on Windows and make it run anywhere within the terminal

Adewale Olaoye's photo
Adewale Olaoye
·Dec 21, 2019·

2 min read

I always had this challenge to setup MongoDB on my machine anytime I switch PC and I have to google search and watch videos that helped me in the past. I felt sharing how I fix it will make me understand better and also refer to it in the future.

I won't bore you with stories. Let's get down to it right away.

I believe you know what Mongodb is and if not you can check them out here mongodb

Go to Mongodb Download Center to download the Community Server

  • Select Windows for the os
  • choose zip on the Package section, then click download

After the download has completed,

  • Extract the file
  • Rename it to mongodb (this is optional but I strongly recommend you rename it for easy access while on the terminal)
  • Create another folder named mongodb-data (this acts as the database store, you can name it anything)
  • Move these two folders to somewhere safe, say
    C:\Users\Adewale
    

N.B. Yours might or will be different depending on where you move these files.

  • Then open cmd using the windows search bar, type cmd, right-click and choose Run as administrator
  • Use cd to switch to the path where you moved the two files mine is

    C:\Users\Adewale\mongodb
    
  • While inside mongodb, do

    cd bin
    

and the path becomes

C:\Users\Adewale\mongodb\bin

then run this command

C:\Users\Adewale\mongodb\bin>mongod.exe --dbpath=C:\Users\Adewale\mongodb-data

you should get a response related to the screenshot below

mongod.PNG

you can also run mongo You should get a response related to the image below

mongo.PNG

and that's it, You have MongoDB installed on your machine but you want more whereby you can run mongo from anywhere within the terminal.

Now, let's fix that now.

  • Copy the path mongodb/bin folder path, mine is
    C:\Users\Adewale\mongodb\bin
    
  • Type Environment Variables on the windows Search tab, Open it, Environment variables.PNG

    then click Environment Variables , You will get a new prompt menu

env3.PNG

  • Click New
  • Give the Variable name PATH and its value the mongodb path value
    C:\Users\Adewale\mongodb\bin
    

6.PNG

Click Ok for all

Go back to the terminal and run mongo from anywhere you you have access to the mongo shell from anywhere in the terminal.

You can checkout these resources for more

thenewboston TraversyMedia

Thanks for reading.