Introduction
In this article, we will learn how to set up and start with MongoDB in Windows Operating System.
MongoDB is a free, open-source, document-oriented cross-platform, not a relational one. It's schema-less, easy to use and scale out, and powerful. It stores the data in the form of JSON, not in tables. It replaces the concept of the row with the document which provides the flexible model. (We will learn about the collection, documents etc. in an upcoming article of this series).
Let’s Begin
Go to MongoDB Official Website in order to download the MongoDB Package (https://www.mongodb.com/download-center#atlas), click on the community server.
Select the Operating System for which you want to download the MongoDB. Click on Download (MSI installer file).
Note.
In case you don’t know the version and architecture of your Windows operating system, then follow the steps mentioned below.
You can find the version and architecture of the operating system in two ways
1. Go to “This PC”, and right click on the windows explorer, click on properties.
2. Open “Command prompt”, then type the below command in order to find the architecture of the operating system, wmic OS get OSArchitecture
Use this command “wmic OS get caption” in the command prompt in order to find the version of the Windows OS Installed in the system.
Now, Install the Downloaded MSI file. Double click on the MSI, and click on next.
Accept the end-user license agreement and click on next.
Choose setup type, select complete. (You can choose custom if you don’t want to install the complete package or want to change the default installation location).
Select the checkbox in case you want to install the MongoD (MongoD is the primary daemon process for the MongoDB system) as a service.
We can even install MongoD as the service later as well (We will learn How to Configure MongoD as a service in the next article).
In the next step, the installer will ask to install MongoDB Compass. Basically, it provides a GUI for MongoDB so that users can explore the data visually.
Click install button in order to Install MongoDB.
Click on Finish if setup is installed successfully.
Before running the MongoD Command, lets set the path variable first. Go to “This PC”, right click on Windows explorer and click on properties.
Click on Advanced system settings.
Click on environment variables button under the advanced tab in system properties dialog.
Select path variable and click on the edit button.
Add new path variable, copy and paste the bin path location of the MongoD files installed. In my system, MongoDB is installed in “C:\Program Files\MongoDB\”. Go to that Directory and open Server folder, then 4.0 folder and then bin folder and copy the path from the explorer “C:\Program Files\MongoDB\Server\4.0\bin”.
In order to run the MongoDB server, we need to configure the data directory where all the databases will be stored . I have created a folder (named it as MongoFiles. You can give any name to that folder) in C drive with “ data/db” as Sub Directory. In my case, the complete path will be “C:\MongoFiles\data\db”.
Note. In case you didn’t already create the data\db directory, Mongo will look in the data\db folder in C: Drive, you will get an error like below:
NonExistentPath: Data directory C:\data\db\ not found., terminating
Once the MongoD command runs successfully, open another command prompt and run the Mongo command. It will connect you to the Mongo shell on your localhost with default port 27017.
Use DB command in order to check your current selected database.
I hope you like this.
Thanks.