Mongosh command not working in Bash shell

First of all, a bit of background: I’m currently working through a Udemy course. The instructor demos installing MongoDB 4.0, then running mongod in hyper (as the instructor is using a Mac), then opening a new shell and running mongo.

I’m trying to achieve the same outcome with MongoDB 6.0.3. I know that now MongoDB uses a separate shell, mongosh. I downloaded the shell and put it in the bin with the other MongoDB downloads. I also set the path environmental variables. When I run the mongod command in the Bash terminal, it seems to be working, but when I open a new Bash shell and run mongosh, it’s giving me errors. I tried the commands for mongo or mongos, and still not working.

I wanted to share screencaps here, as I think that’d be more helpful, but it looks like I’m going to need to clean off some diskspace to run Photoshop, so for now I hope these descriptions will help. Here is what I’m seeing in the Bash shell when I run each command:

“$ mongosh
bash: mongosh: command not found”

“$ mongo
BadValue: error: no args for --configdb
try ‘C:\Program Files\MongoDB\Server\6.0\bin\mongos.exe --help’ for more information”

I double-checked, and my mongosh file is definitely in “C:\Program Files\MongoDB\Server\6.0\bin”, which is the path I set in the environmental variables section.

I followed what this guy did in the video: Mongo command is not working/found in MongoDB 6.0+ || MongoDB error fix - YouTube – with the one difference being that I put my mongosh file with the other MongoDB files in the bin folder… though I don’t see that this would make a difference. But when I run the “mongosh” command in Bash, I get the error above. I’m confused, as it seems to work fine for him in the tutorial video, so I came here, as I’m quite frustrated with trying to troubleshoot at this point. I’ve been troubleshooting MongoDB installations issues for a while now, between this and other differences in the updated version, and browsing here and Stack Overflow, but still confused as to why it’s not working.

Any help would be appreciated! Thanks!

Edit: Oh my gosh. I just decided to try the command CLI rather than the Bash shell, and… it works on the command prompt, but not the Bash shell. I suppose I can use the command prompt, but now I’m confused why it’s not working in the Bash shell. I feel a little silly realizing this after typing all that, but I do prefer to work in the Bash shell if possible.

1 Like

Hi @Amber_Adamson! I don’t have a complete answer for you, but here’s the troubleshooting that I’d do if I were in your situation:

  • echo $PATH – Just double-checking that the path environment variable is set to what it is supposed to be set
  • which mongosh vs. type mongosh – Does the behavior for finding mongosh differ between bash itself and its subprocesses? (Maybe also compare with which mongo / which mongod just to be sure that those pick up the right directory)
  • hash -r – Clear bash’s cache for executable paths, then run mongosh again
  • And finally, can you run mongosh by specifying its full path inside bash, or is it only typing the literal single word mongosh that fails?

Finally, this is not related to troubleshooting but points to something being wrong in general:

$ mongo
BadValue: error: no args for --configdb
try ‘C:\Program Files\MongoDB\Server\6.0\bin\mongos.exe --help’ for more information

mongo and mongos are different executables, so if mongo self-identifies as mongos and reports an error that only mongos should ever really report, there’s most likely something else wrong with the MongoDB installation here as well.

How are you running bash on Windows? Is this in WSL?

You would need to install mongosh inside WSL if you are.