How to Setup MongoDB & Mongo Shell ?

How to Setup MongoDB & Mongo Shell ?

·

4 min read

Installation or setup of MongoDB?

You can install MongoDB using two different methods one is using MSI and another is using zip. Here, we will discuss how to install MongoDB using MSI, so you need to follow each step carefully:

Steps to install MongoDB on Windows using MSI

Step 1: Go to the MongoDB Download Community Link to download the MongoDB Community Server and click on "select package" button mongo-installation1.png Step 2 : Here, You can select any version, Windows, and package according to your requirement. For Windows, we need to choose :

  • version : Always choose current version as per now version is : 7.0.5 (current)
  • OS: Windows x64
  • Package: msi
    And click on download. mongo-installation2.png Step 2: When the download is complete open the msi file and click the next button in the startup screen: mongo-installation3.png Step 3: Accept the End-User License Agreement and click the next button: mongo-installation4.png Step 4: Now select the complete option to install all the program features. Here, if you can want to install only selected program features and want to select the location of the installation, then use the Custom option: mongo-installation5.png Step 5: Select “Run service as Network Service user” and copy the path of the data directory. Click Next: mongo-installation6.png Step 6: You can select to install mongoDB compass as well to see the collection in GUI. mongo-installation7.png Step 7: Click the Install button to start the MongoDB installation process: mongo-installation8.png Step 8: After clicking on the install button installation of MongoDB begins: mongo-installation9.png Step 9: Now click the Finish button to complete the MongoDB installation process: mongo-installation10.png Step 10: Now we go to the location "C:\Program Files\MongoDB\Server\7.0\bin" in your system and copy the bin path: mongo-installation11.png Step 11: Now click on window button from the taskbar and search for "environment variables" and then click to open them. mongo-installation-12png.png Step 12: click on "environment variable" button and then choose path from the user variable (upper section) and then click on "Edit" button. mongo-installation-13png.png Step 13: Now click on "New" button and then paste that path which we copied in step 10. and then click on "ok" button. mongo-installation-14.png Step 14: Now paste the same path in system variable section by selecting "path" and then click on "edit" button and paste inside them as we done in step 13. mongo-installation11.jpg
  • Now if you think why we paste the path in both user variable section and system variable section then the answer is that user variable are only accessed by currently logged-in user but system variables are accessed by all the user account globally in our system. Step 15: Now Goto command prompt (cmd) and check for the mongo version by typing following command : mongod --version mongo-installation5.jpg
  • if you get the version detail that means your mongdb is completely installed.

Step 16: Now to run mongo shell in our command prompt then we have to install mongo shell separately because 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. so, download the MongoDB shell from the link https://www.mongodb.com/try/download/shell. mongo-installation.jpg Step 17: When the download is complete open the msi file and click the next button in the startup screen: mongo-installation1.jpg Step 18: Now copy the default path which is given in destination folder and if you want to change the destination path then click on "change" button and change the path but for now we just copy the path. mongo-installation2.jpg Step 19: Now click on "Install" and wait till the process complete. mongo-installation3.jpg Step 20: Now click on "finish" button. mongo-installation4.jpg Step 21: Now go to the location which we copied in step 18 "C:\Users\user\AppData\Local\Programs\mongosh" in your system and check that "mongosh" and other files are present and copy the path: mongo-installation9.jpg Step 22: Now paste the path in environment variable. mongo-installation10.jpg Step 23: Now Goto cmd and type command "mongosh" and finally your shell will start. mongo-installation7.jpg Now you can run your mongoDB commands and can also perform mongoDB queries here.

Thanks for reading, i will write more blogs on mongoDB where i will cover all the mongoDB queries from basic to advanced and if this blog get helpful to you then please like 👍 and share...