简体   繁体   中英

bash: mongo: command not found

I installed mongodb on my system, but when I go to bin directory using Git and type mongo, this happens.

图片

What shall I do?

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.

如果您使用的是 git bash,请使用以下命令

$ ./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!

Use mongosh intead of mongo. This solved my problem using docker

In later versions of this, you have to download mongo shell. Once you downloaded if zip extracts the files and moved folder to your program's folder. Renamed the folder mongosh. Copy the path and added to your environment variables path. it should look like this C:\Program Files\mongosh\bin. Next, if you haven't done so already. Create data folder in your root directory in my case windows c drive. Create a subfolder in the data folder called db. make sure this folder is in the root directory and not in the program's folder. Once this is done, close all the prompt windows and run again mongod and again run now not mongo but mongosh, and it will allow you to type in your code. I had to delete my previous created data folder that i created previous to installation of MongoDB hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM