Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mongo command not recognized when trying to connect to a mongodb server

Tags:

mongodb

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?

like image 766
Kristian82 Avatar asked Feb 24 '13 16:02

Kristian82


People also ask

Can not connect to MongoDB?

These are some of the solutions: Ensure that your MongoDB instance is running: Compass must connect to a running MongoDB instance. Also check you have installed MongoDB and have a running mongod process. You should also check that the port where MongoDB is running matches the port you provide in the compass connect.

Why MongoDB command not found?

mongo is not recognized as an internal or external command This error usually occurs because the system can not find the executable that you are asking to launch so to launch the file you have to provide the full path and after that, it will run without any issues.

Which command is used to connect with MongoDB?

To open up the MongoDB shell, run the mongo command from your server prompt. By default, the mongo command opens a shell connected to a locally-installed MongoDB instance running on port 27017 . Try running the mongo command with no additional parameters: mongo.


3 Answers

You need to add Mongo's bin folder to the "Path" Environment Variable

Here's how on Windows 10:

  1. 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:

This is what Mongo's bin folder looked like for version 3.4, the important thing is it's whatever folder contains mongod.exe. 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.

  1. Copy the path to the bin folder. It should be C:\Program Files\MongoDB\Server\3.4\bin\ (Or whatever version you're using)

  2. Press win, type env, Windows will suggest "Edit the System Environment Variables", click that.

How to find the system environment variables.

  1. On the Advanced tab, click "Environment Variables"

The Advanced tab in System Properties contains the Environment Variables.

  1. Highlight the "Path" variable, click "Edit":

You want to edit the Path variable to add Mongo's bin folder to it.

  1. This will bring up the "Edit environment variable" window, click "New"

Add a new folder to the Path variable

  1. This will start a new line in the list of folders:

A new line in the Path variable.

  1. Paste your path to the bin folder. Make sure it ends with a \ like so:

Paste the location of the bin folder.

  1. Press "OK", "OK", "OK"

Now you should be able to run mongod and mongo from anywhere in a command window.

like image 161
Travis Heeter Avatar answered Oct 10 '22 07:10

Travis Heeter


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).

like image 79
br3w5 Avatar answered Oct 10 '22 08:10

br3w5


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\

like image 28
dilion.dani Avatar answered Oct 10 '22 08:10

dilion.dani