The traditional MongoDB shell, ‘mongo.exe,’ is no longer included in the server binaries after MongoDB 6.0. When you install MongoDB 6.0 or later, you will not see the ‘mongo.exe’ file in your ‘bin’ folder. This change is mentioned in the’ Compatibility Changes in MongoDB 6.0’ section.
Introducing the New MongoDB Shell: mongosh
MongoDB introduced a new shell called ‘mongosh’ to replace the legacy ‘mongo’ shell. The ‘mongosh’ shell provides a REPL environment for working with MongoDB deployments in Atlas, locally, or on another remote host. You can use the MongoDB Shell to test queries and interact with data in your MongoDB database.
How to Install Mongosh?
You must first download ‘mongosh’ from the MongoDB Download Center (https://www.mongodb.com/try/download/shell). After downloading, copy the contents of the ‘bin’ file from the downloaded zip file to the ‘bin’ file in your MongoDB folder.
After installing it, you must add the path to ‘mongosh’ to your system variables. Then, type ‘mongosh --version’ in your terminal to test if it was installed correctly.
Follow the steps as shown in the image below.
- Open Windows Settings and click on ‘Advanced system settings’
- Click Environment Variables
- Select the Path variable
- Click on Edit…
- Click on New
- Insert the path (I used a custom path), and confirm by clicking OK.
To connect to a MongoDB instance running on your localhost with the default port 27017, type’ mongosh’ into your terminal. The MongoDB manual (https://www.mongodb.com/docs/mongodb-shell/) provides more information on how to use ‘mongosh.’
Conclusion
While removing the legacy’ mongo’ shell from MongoDB versions 6.0 and newer may initially appear perplexing, the new’ mongosh’ shell provides a robust and versatile environment for working with MongoDB databases. Follow these steps to install and use’ mongosh quickly’.