How to use the new mongo shell “mongosh” in windows
I just found out that there’s a new way to connect with your mongoDB deployment which promises to be “the quickest way to connect to MongoDB and Atlas to work with your data and configure your database”.
I though of giving it a try and because I’m such a noob, it took me a couple to tries to figure it out.
Step1: Download the MongoDB Shell (beta)
When you click the Download Now
button, you’ll be provided with a .zip
file. Just go ahead and extract it. You’ll see a mongosh.exe
file, and this is where I stumbled the first time. I just went ahead and double clicked on it and it opened a new terminal and tried to connect to the local mongoDB instance. Which would’ve been fine if I actually had a running local instance.
Step 2: Open mongosh.exe in CMD
After a failed google attempt to find a tutorial to connect to a remote instance, it dawned upon me that this file is not meant to be run standalone but to be used as a command in CMD. I hit windows + r
and entered cmd
to start a new instance of command prompt. I opened the directory where mongosh.exe was laying around basking in the sun. I then entered the following command
And voila! I had a connection
You can stop here and continue to use mongosh
as it is or if you’re a lazy ass like me then add the path to environment variables and then you can use the mongosh
command from anywhere in the command prompt.
Step 3: Add mongosh.exe to path (optional)
This is easy.
First I saved the mongosh.exe
file in C:\Users\anurut\mongosh
(you can keep it wherever you want). Then hit ‘windows’ key and type environment variables
and click opened Environment Variables window by clicking on the text underlined in the screenshot below
Then I clicked on the Environment Variables...
button at the bottom
Further, I selected Path
in User Variables
in the following window and clicked Edit...
The next step is to click on New
and enter the location of your mongosh.exe
file. In my case it is C:\Users\anurut\mongosh
and click every OK
button that you see to complete this step.
Hurray! now you’ve lazy’d up the launch of mongosh. Just open CMD, type mongosh <mongodb connection string>
and press enter.
Please shower some claps if you found this article useful.