Can't run mongo command on windows [duplicate] - mongodb

This question already has answers here:
mongo.exe not installed in Version 6.0.0
(7 answers)
mongosh is a valid command but mongo is not found
(2 answers)
Closed 13 days ago.
I tried t to set up Community MongoDB on my windwos pc. I followed the installation process and tried to set up the environment variables. I copied the pathes from my explorer, so the pathes should be correct. screenshot of my env
Nonetheless I can't use any mongo commands on my command shell. Anytime I try to run "mongo" or "mongodb" or "mongo --version" it says "command is either misspelled or couldn't be found". screenshot of my cmd shell
When I use the command "mongod" some strange code appears screenshot of my cmd shell
How can I solve this problem?

Found the solution: you have to set up mongoshell first and then you can use the command "mongosh" to use it with the windows command. This tutorial helped me set everything up: youtube.com/watch?v=V-d6VAYrjeQ

Related

Want to start mongodb but facing this kind of error'mongo' is not recognized as an internal or external command, operable program or batch file' [duplicate]

This question already has answers here:
mongo.exe not installed in Version 6.0.0
(7 answers)
Closed 3 months ago.
I'm trying start mongo in cmd:
C:\Users\Vishal Bramhankar>mongo
'mongo' is not recognized as an internal or external command,
operable program or batch file.
What I missed here?
After MongoDB version 6.0 and onwards we need to install MongoDB Shell separately.
Configure below path in envarinment variables
C:\Program Files\mongosh-1.6.1-win32-x64\bin
Close your cmd and open the new cmd again and run below command:
C:\Users\Vishal Bramhankar>mongosh
Run below one for knowing DBs:
test> shows dbs
MongoDB shell installation:
https://www.mongodb.com/try/download/shell

"Code" command not working, on different user in ubuntu wsl [duplicate]

This question already has an answer here:
WSL2 doesn't work after using su to change user
(1 answer)
Closed 4 months ago.
So, I have 2 users in my Ubuntu WSL, and if I try to run code ., when the wsl opens in the main user as default it works fine, but when I switch to second user using su second_user, then running code . gives the following error:-
Command 'code' not found, did you mean:
command 'tcode' from deb emboss (6.6.0+dfsg-11ubuntu1)
command 'ode' from deb plotutils (2.6-11)
command 'cde' from deb cde (0.1+git9-g551e54d-1.2)
command 'node' from deb nodejs (12.22.9~dfsg-1ubuntu3)
command 'cdde' from deb cdde (0.3.1-1build1)
Try: sudo apt install <deb name>
Then, if I go back to my previous user, then it stops working there as well, and gives the same error.
So, a fix that I found for my situation was to change the default user of the WSL, by entering the following command in PowerShell of windows.
ubuntu config --default-user second_user
Where the general syntax of the command will be:-
<distro_name> config --default-user <username>

Trouble setting up Sublime Text 3 to work with MongoDB [duplicate]

I'm using Mac Lion. I was using mongodb version 1.4. I wanted to upgrade to 1.8.5 and I followed http://shiftcommathree.com/articles/how-to-install-mongodb-on-os-x step wise replacing each mongodb-osx-x86_64-1.4.0 by mongodb-osx-x86_64-1.8.5. Everything goes smooth. I tried:
mongod
it's ok. I can access localhost:28017
but,
mongo
shows command not found
How can I fix this?
You need to add the path to "mongo" to your terminal shell.
export PATH=$PATH:/usr/local/mongodb/bin
Did you do the last step with paths.d? If so, try restarting your terminals.
Do you have a good reason for using 1.8.5? The current stable is 2.0.4, and it has many useful upgrades from 1.8.x
Starting from Mongodb version 6.0 mongo was replaced by mongosh
For readers in 2021:
export PATH="$PATH:/usr/local/opt/mongodb-community#3.6/bin"
You'll have to add the location of the Mongo binary to PATH.
Follow the steps below in order to make the PATH variable permanent:
Open Terminal and navigate to your user directory.
Run touch ~/.bash_profile and then open ~/.bash_profile.
In TextEdit, add export PATH="<mongo-directory>/bin:$PATH" (Keep the quote marks - related to white spaces).
Save the .bash_profile file and Quit (Command + Q) Text Edit.
Run source ~/.bash_profile.
Run echo $PATH and check if the you see that the Mongo binary was added.
(*) Notice that the PATH variable is now available only for the current terminal and not to processes that were already started in the session.
In order to make it available outside the current terminal - you'll have to logout and login.
1.Go to your [mongodb installation dir]:
cd <mongodb installation dir>
2.Type ./bin/mongo to start mongo:
./bin/mongo
Read More
Note :
If above command gives error
Failed global initialization: BadValue Invalid or no user locale set. Please ensure LANG and/or LC_ environment variables are set correctly.*
Run bellow command: Read More
export LC_ALL=C
How can find installation directory
find / -name "mongodb"
You can also set path
export PATH=$PATH:<mongodb installation dir>/bin
documentation
export PATH={mongodb-install-directory}/bin:$PATH
In Mac:
Go into Bash Profile:
vi ~/.bash_profile
Add Path of Installation of MongoDB:
export PATH=$PATH:/usr/local/opt/mongodb-community#4.2/bin
Reload the Bash Profile:
source ~/.bash_profile
You can navigate to the mongo directory using the command line and then start MongoDB with
./mongodb
I was facing the same problem this worked for me.
you need to install mongodb shell to ge the mongo command working.
Download link
I didn't have the right mongo command line tools installed. This from Brew worked for me though.
brew install mongodb-community
just a little recommandation, if your path has a space just wrap the whole path with quote or doublequote
example : C:\Program Files\MongoDB\Server\4.2 . notice the space in "Program Files"
export PATH=$PATH:"C:/Program Files/MongoDB/Server/X.X/bin"
in place of mongo command use mongosh command and it will work.

pretty print in mongo shell not working - MongoDB 2.6 + Yosemite + ZSH [duplicate]

This question already has an answer here:
How do I get colorized query output and shell in MongoDB?
(1 answer)
Closed 8 years ago.
I'm running the mongo shell by invoking mongo at the command line. The result is a bland shell experience. I would like to see colored JSON output, etc. I tried running:
> db.my_collection.find().pretty()
but it didn't work.
I also tried adding the following line to ~/.mongorc.js:
DBQuery.prototype._prettyShell=true
but it didn't work.
Try the MongoDB shell enhancement. You can make particular tweaks after you clone the repo.

Can we run mongoDB shell at any location/directory in unix [duplicate]

I'm using Mac Lion. I was using mongodb version 1.4. I wanted to upgrade to 1.8.5 and I followed http://shiftcommathree.com/articles/how-to-install-mongodb-on-os-x step wise replacing each mongodb-osx-x86_64-1.4.0 by mongodb-osx-x86_64-1.8.5. Everything goes smooth. I tried:
mongod
it's ok. I can access localhost:28017
but,
mongo
shows command not found
How can I fix this?
You need to add the path to "mongo" to your terminal shell.
export PATH=$PATH:/usr/local/mongodb/bin
Did you do the last step with paths.d? If so, try restarting your terminals.
Do you have a good reason for using 1.8.5? The current stable is 2.0.4, and it has many useful upgrades from 1.8.x
Starting from Mongodb version 6.0 mongo was replaced by mongosh
For readers in 2021:
export PATH="$PATH:/usr/local/opt/mongodb-community#3.6/bin"
You'll have to add the location of the Mongo binary to PATH.
Follow the steps below in order to make the PATH variable permanent:
Open Terminal and navigate to your user directory.
Run touch ~/.bash_profile and then open ~/.bash_profile.
In TextEdit, add export PATH="<mongo-directory>/bin:$PATH" (Keep the quote marks - related to white spaces).
Save the .bash_profile file and Quit (Command + Q) Text Edit.
Run source ~/.bash_profile.
Run echo $PATH and check if the you see that the Mongo binary was added.
(*) Notice that the PATH variable is now available only for the current terminal and not to processes that were already started in the session.
In order to make it available outside the current terminal - you'll have to logout and login.
1.Go to your [mongodb installation dir]:
cd <mongodb installation dir>
2.Type ./bin/mongo to start mongo:
./bin/mongo
Read More
Note :
If above command gives error
Failed global initialization: BadValue Invalid or no user locale set. Please ensure LANG and/or LC_ environment variables are set correctly.*
Run bellow command: Read More
export LC_ALL=C
How can find installation directory
find / -name "mongodb"
You can also set path
export PATH=$PATH:<mongodb installation dir>/bin
documentation
export PATH={mongodb-install-directory}/bin:$PATH
In Mac:
Go into Bash Profile:
vi ~/.bash_profile
Add Path of Installation of MongoDB:
export PATH=$PATH:/usr/local/opt/mongodb-community#4.2/bin
Reload the Bash Profile:
source ~/.bash_profile
You can navigate to the mongo directory using the command line and then start MongoDB with
./mongodb
I was facing the same problem this worked for me.
you need to install mongodb shell to ge the mongo command working.
Download link
I didn't have the right mongo command line tools installed. This from Brew worked for me though.
brew install mongodb-community
just a little recommandation, if your path has a space just wrap the whole path with quote or doublequote
example : C:\Program Files\MongoDB\Server\4.2 . notice the space in "Program Files"
export PATH=$PATH:"C:/Program Files/MongoDB/Server/X.X/bin"
in place of mongo command use mongosh command and it will work.