In this article I am writing how to install, general configuration MongoDB and testing its successful installation by inserting a few city names and displaying the inserted information from collection. To install MongoDB you need to download the latest production release of MongoDB from the MongoDB downloads page and you need to scroll down to the previously clicked downloads page until you reach the following screen and select the appropriate operating system tab.
I have a Windows 10 installed on my computer that’s why I selected Windows tab. You need to choose the correct version from the drop down and click on the DOWNLOAD(MSI) button at the left corner of the box.
Once the file is downloaded, double click on the downloaded file and complete the installation process as wizard leads you. In my computer MongoDB is installed at C:\Program Files\MongoDB\Server\3.0\bin folder.
Inside C:\Program Files\MongoDB\Server\3.0\bin folder you can see a bunch of executable files (.exe). Among them mongo.exe is the client shell and mongod.exe is the server. Before running mongod and mongo from Command Prompt, you need to add Path Environment Variables for MongoDB. Follow the following steps to set up the PATH environment variable.
Right click on Computer
Click on Properties
Click on Advanced System Settings which opens up a pop up box as below
Click on Environment variables
Now you need to create default directory \data\db for MongoDB. You need to create a folder \data\db in C: drive. Once default directory for MongoDB is created, you need to open Command Prompt and type mongod which opens MongoDB server displaying logs and if you read the log messages, you come to know that the server is listening MongoDB clients at port 27017. To keep the directory in other drives with different name than \data\db in C:, you need to give the following command instead of only mongod in command prompt.
mongod --dbpath C:\mongodata
Next you need to open another Command Prompt and put the command mongo which starts the mongo shell and connects with the mongod server via localhost at port 27017.
Now the MongoDB is installed successfully. You can insert a few city names to test whether it is working properly or not. In mongocommand prompt type the following commands to insert a few city names and displaying them from the cities collection.
Fig : Opening mongo client, inserting two cities and displaying the document