Reputation:
I installed mongodb on my system, but when I go to bin directory using Git and type mongo, this happens.
What shall I do?
Upvotes: 9
Views: 27625
Reputation: 5902
The problem can be solve if you add MongoDB path in the system variables(Next steps are configure in W10):
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.
Upvotes: 8
Reputation: 1
check the path
mongod.cfg
mongod.exe
mongod.pdb
**mongos.exe**
mongos.pdb
despit adding alias mongo="/c/Program\ Files/MongoDB/Server/4.0/bin/mongo.exe"
it should be alias mongo="/c/Program\ Files/MongoDB/Server/4.0/bin/mongos.exe"
Upvotes: 0
Reputation: 1
I will add to this, in case others had my error. I set the paths in System and everything, but got the same error after following the answers above in my VSCode terminal. I found that if I ran the command from Git bash instead of VSCode terminal, I did not get an error. Make sure you are using Git bash.
Upvotes: 0
Reputation: 1
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.
Upvotes: 0
Reputation: 11
Use mongosh intead of mongo. This solved my problem using docker
Upvotes: 1
Reputation: 115
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.
Hope that helps!
Upvotes: 2
Reputation: 14436
if you're using git bash, use the following command
$ ./mongo
Upvotes: 5