mongod command not recognized when trying to connect to a mongodb server
You need to add Mongo's bin
folder to the "Path" Environment Variable
Here's how on Windows 10:
- Find Mongo's bin folder.
If you're not sure where it is, it's probably in C:\Program Files\MongoDB\Server\3.4\
3.4 was the latest stable version at the time, this will be different for you probably.
It should look like this:
Notice this is the path to mongo.exe and mongod.exe. Adding this folder to the Path variable is telling Windows to search in this folder for executables matching your command when you run something in cmd. The search starts with the current working dir, and if it doesn't find your exe, goes on to search all the paths in Path till it finds it or it doesn't and it gives you that error you saw.
Copy the path to the bin folder. It should be
C:\Program Files\MongoDB\Server\3.4\bin\
(Or whatever version you're using)Press win, type
env
, Windows will suggest "Edit the System Environment Variables", click that.
- On the Advanced tab, click "Environment Variables"
- Highlight the "Path" variable, click "Edit":
- This will bring up the "Edit environment variable" window, click "New"
- This will start a new line in the list of folders:
- Paste your path to the bin folder. Make sure it ends with a
\
like so:
- Press "OK", "OK", "OK"
Now you should be able to run mongod
and mongo
from anywhere in a command window.
You need to run mongod
first in one cmd window then open another and type mongo
. Make sure you updated your Windows Path environment variable too so that you don't have to navigate to the directory you have all of the mongo binaries in to start the application. To update the Path variable:
Go to Control Panel > System & Security > System > Advanced System Settings > Environment Variables > navigate to the Path variable hit Edit and add ;C:\mongodb
to the Path (or whatever the directory name is where MongoDB is located (the semi-colon delimits each directory).
It is probably too late, but for the sake of others (like me) who faced the same problem. It is all about the little '\' at the end of the path variable. When you insert the path to MongoDB's bin directory at the end of the PATH windows variable, do not forget to put the '\' (Backslash) at the end, which tells windows it is a directory and not an executable named bin... e.g. I:\Program Files\MongoDB\Server\3.0\bin\