bash: mongo: command not found

The problem can solve if you add MongoDB path in the system variables:

Go to this path "Control Panel\System and Security\System" on the left you should see some options click on "Advanced system settings" after this click on "Environment Variables" at the System variables should be one option "Path" click that option and "Edit" it, add "New" variable on this system, in my case, is "C:\Program Files\MongoDB\Server\4.2\bin" and save this change.


if you're using git bash, use the following command

$ ./mongo

I've just had the same problem and did this to solve it. I hope it helps (late, but to be sure it is answered).

Open GitBash and type the following:

1) cd.. // to go to the root directory.

2) touch .bash_profile // creates a hidden file to set up the shortcut

3) notepad .bash_profile // this opens that hidden file with notepad. You can also do it with VIM if you want to master you command console skills...

4) paste these two command lines:

alias mongod="/c/Program\ Files/MongoDB/Server/4.0/bin/mongod.exe"

alias mongo="/c/Program\ Files/MongoDB/Server/4.0/bin/mongo.exe"

!!! Check that your files are also in the same route as these. If not, modify what's needed. Mind the space between "\ Files" because this gave trouble too. You may need to change the version in case you don't have 4.0.

5) Save the file. Close Notepad.

6) At Gitbash again: CRTL + C, and close the console.

7) Open Gitbash again, go to the root, and type: mongo --version. If you see something like: MongoDB Shell version v4.0.10... you've been successful (see image). If not, check the route of the document you've put into the bash profile, and be sure to fully restart the bash console after.

Mongo install success

Hope that helps!

Tags:

Mongodb