mongo command not recognized when trying to connect to a mongodb server
MongodbMongodb Problem Overview
I am following the tutorials at docs.mongodb.org, I have completed the first tutorial which was to install mongodb on a Windows machine. I am now at the second stage which is getting started with mongodb development.
I am stuck at the first stage of this section which instructs me to type mongo
into a system prompt. When I do this I simply get an error message saying the following:
'mongo' is not recognized as an internal or external command, operable program or batch file
I know this is probably something quite simple that I am doing wrong, does anyone have any ideas?
Mongodb Solutions
Solution 1 - Mongodb
bin
folder to the "Path" Environment Variable
You need to add Mongo's 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.
Solution 2 - Mongodb
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).
Solution 3 - Mongodb
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</strong>
Solution 4 - Mongodb
Seems like, The environmental variable is not correctly set up.
Go to the mongodb installation folder and get the executable files (mongo.exe, mongod.exe etc) location. (In my case) Something like :
C:\Program Files\MongoDB\Server\3.2\bin
Then go to :
Panel > System & Security > System > Advanced System Settings > Environment Variables
Find the PATH
variable and edit its value. Then add C:\Program Files\MongoDB\Server\3.2\bin
and don't forget to separate each values with ;
. Now confirm and exit.
Solution 5 - Mongodb
if still not working for you then just close all of your command prompts and then again open and run mongo, mongoimport, mongodb from anywhere it ll work because after setting the path variable command prompt should be restarted.
Solution 6 - Mongodb
You need to be in the right directory, i.e.
C:\Program Files\MongoDB\bin
and the path you are installing into needs to be the correct one
i.e.
mongod --dbpath
C:\Users\Name\Documents\myWebsites\nodetest1
A folder named "data" must also exist in your project folder.
Solution 7 - Mongodb
For add environment variable please add \ after bin like below
C:\Program Files\MongoDB\Server\3.2\bin\
Then try below code in command prompt to run mongo server from parent folder of data folder.
mongod -dbpath ./data
For my case I am unable to run mongo from command prompt(normal mode). You should run as administrator. It also works on git bash.
Solution 8 - Mongodb
This worked for me:
.\mongod --dbpath c:\......
Solution 9 - Mongodb
First, make sure you have the environment variable set up.
- Right click on my computer
- properties
- advanced system settings
- environment variables
- edit the PATH variable. and add ;"C:\mongoDb\bin" to the PATH variable.
Path in the quotes may differ depending on your installation directory. Do not forget the last '' as it was the main problem in my case.
Solution 10 - Mongodb
Adding MongoDb
bin path in Environment path with \
worked for me
This is what my system path
C:\ProgramData\Oracle\Java\javapath;
...
...
Other path variables
...
;C:\Users\hitesh.sahu\AppData\Local\Android\sdk\platform-tools
;C:\Program Files\MongoDB\Server\3.2\bin\
Make sure:-
- Environment path must not have space between them
- Environment path must be saparated by
;
Solution 11 - Mongodb
Apart from having a Path
variable, the directory C:\data\db
is mandatory.
Create this and the error shall be solved.
Solution 12 - Mongodb
before using MongoDB you have to run it locally to do that:
- go to
bin
folder you will find atC:\Program Files\MongoDB\Server\4.2\bin
- open
mongod.exe
. will open a new terminal with server details. - open
mongo.exe
. will open the shell which allows you to interact with the database.
Solution 13 - Mongodb
1.To begin using MongoDB, Open CMD with admin privilege and type : "C:\Program Files\MongoDB\Server\4.2\bin\mongo.exe"
2.To create data directory(open another cmd terminal)
cd C:
md "\data\db"
- To start your mongo DB database, type in cmd the following lines: "C:\Program Files\MongoDB\Server\4.2\bin\mongod.exe" --dbpath="c:\data\db" (The --dbpath option points to your database directory.) [you can also do step 2 and 3 first and then step 1]
ref:https://docs.mongodb.com/manual/tutorial/install-mongodb-on-windows/
Solution 14 - Mongodb
mostly, this is not working because you haven't set the path, in my case too I haven't set a path. so this can be solved by following the steps.:
-
Go to the control panel
-
Click on system and security
-
then click on the system
-
click on the advanced system setting
-
click on environment variable
-
click on the path in user variables
-
Edit the path
-
Add a new path
-
(copy the path from local discs c /program files/mongodb/bin), it should look similar to this C:\Program Files\MongoDB\Server\5.0\bin
-
paste it there and click ok
-
close the vs code and reopen it
Solution 15 - Mongodb
Just use mongotop
instead of mongod
in your terminal.
Solution 16 - Mongodb
putting forward slash "/" at the end of path to bin of mongodb solved my problem.