Introduction
This article will describe on how to access MongoDB shell. The execution of the MongoDB shell is in the Microsoft Windows 10. This article has a strong connection with several articles available before. Those articles are the article with the title of ‘How to Perform MongoDB Offline Installation in Microsoft Windows 10’ available in this link. Another article with the title of ‘How to Start MongoDB Service in Microsoft Windows’ in this link. Moreover, the last article with the title of ‘How to Access MongoDB Shell in Microsoft Windows’ in this link.
The process to achieve it is done by defining an environment variable. It is an environment variable with the value of the full absolute path of the MongoDB installation folder. In this context, the path is available in ‘C:\Program Files\MongoDB\Server\4.4\bin’. There are several steps for achieving it. The first one is defining the MongoDB installation path using an environment variable. The second step is to add the MongoDB installation path environment variable to the Path environment variable. The ‘Path’ environment variable is representing all of the available path to be recognized by the operating system. The last step is the testing part.
Adding New Environment Variable for Defining MongoDB Installation Folder
Specifically, it is not the main installation folder of the MongoDB. But the actual target is the binary files folder of the MongoDB installation folder. So, the following are the steps to accomplish it :
1. Just access the Environment Variables windows dialog box. Type it in the column of ‘Type here to search’ available in the task bar. The following is the image of it :
2. The following image is displaying the entry process in the column of ‘Type here to search’ to execute the Environment Variables windows dialog box :
3. Click the ‘Edit the system environment variables’ row. The following windows dialog box will appear :
4. Next, just click the Environment Variables… button. The following windows dialog box will appear :
5. In order for executing ‘mongo’ command in any folder directory location or path. Just create a new variable by clicking the New… button. It is to define the folder directory location or path of the MongoDB installation folder directory. After clicking the New… button, the following image will appear :
6. Just fill the variable name with any name. But make sure to remember the name. Actually, there is some sort of convention or rule to give the environment variable name with an uppercase letter and connect each of the word with an underlined character. In case of the variable value, don’t forget to check the location of the binary file of the MongoDB for accessing MongoDB shell. In this case, the path is in ‘C:\Program Files\MongoDB\Server\4.4\bin’. Click the OK button after finishing the entry on the above windows dialog box for defining New System Variable.
Adding MongoDB Environment Variable to the Path Environment Variable
1. Next step, just access the Environment Variable list as in the fourth step, and select the ‘Path’ environment variable as follows :
2. After selecting the Path row of the System Variables, click Edit… button. The following windows dialog box will appear :
3. Click the New Button as in the above windows dialog box. The following display of the windows dialog box will appear :
4. Just fill the above new entry with the previous variable name definition. In the above definition, there is a new variable definition of the installation path of the MongoDB. The variable name is ‘MONGODB_HOME’. So, in order for the system path recognize the MongoDB installation path, add it into the path variable name definition. Add it as in the following image :
5. Click the ‘OK’ button to finish the process. So, adding the ‘MONGODB_HOME’ environment variable that has the path definition of the binary file of MongoDB shell command to the ‘Path’ environment variable of the operating system is finish.
Testing to Execute MongoDB Shell from any path
Finally, don’t forget to execute the MongoDB shell command in the Windows Command Prompt. Actually, any type of user executing the Windows Command Prompt is possible to execute the MongoDB shell command. It is exist as in the following image :
As in the above image output, there is no need to direct or to access to the MongoDB installation folder or path first to execute the MongoDB she. On the contrary, just type the command ‘mongo’ in any current working directory. In the above example, it is in ‘C:\Windows\system32’. So, overall the process is a success.