Before exploring MongoDB, Let’s see how to install MongoDB on windows.
In this tutorial, we are going to install MongoDB version 3.6.5 on windows 10. You can download MSI file for MongoDB from this link. At the time of reading, there may be updated version of MongoDB that you can download. Though I am using windows 10 here, you can follow the same steps for Windows 7 and 8.
Once MSI file is downloaded, you can double-click on it to start the installation process. It is a straightforward installation, and you can keep most of the things as default. Once the installation is complete, you should have MongoDB files at location “C:\Program Files\MongoDB\Server\3.6”.
Setting up the environment variable
We need to set up the environment variable for windows so that we can access MongoDB from the command prompt directly. We can open environment variable dialog box by going Control Panel -> System and Security -> System -> Advanced System Settings ->Environmentt Variables in Windows 10.
In the System variable section, select path variable and edit it. Then we need to click on new and then add path of MongoDB installation till bin folder that is “C:\Program Files\MongoDB\Server\3.6\bin”
Creating database directory
There is one more thing that we need to do before starting MongoDB server. MongoDB needs some location to store its data. By default, MongoDB searches for data folder in C drive. So let us create a folder in C drive with name data and inside that another folder named db. Now you should have a structure like “C:\data\db”. MongoDB will store all data on this location.
Now we are all set up. Let us check if MongoDB is working on our machine or not. Firs,t we need to launch MongoDB server. Open one command prompt and write “mongod” in it.
You should get output like above if everything is correct. We can see in highlighted part that MongoDB server is using “C:\data\db” and listening on port 27017 for a new connection. Let us open new prompt and write mongo. This will connect to already running MongoDB server. Remember, You should always run MongoDB server first then only you can connect to it. Let us run show dbs command and check its output.
If you see some output like this, then MongoDB is correctly installed on your system, and you are ready to go. If you are facing some errors, then please follow all steps correctly from the start or you can comment issue here and ask for help.
We have installed MongoDB on Windows machine. We are ready to learn about MongoDB now. Till next time, Keep learning !!!
I am passionate about data analytics, machine learning, and artificial intelligence. Recently I have started blogging about my experience while learning these exciting technologies.