Getting Started With MongoDB
Getting Started With MongoDB
In this article, we will learn how to set up and start with MongoDB in Windows Operating System.
Join the DZone community and get the full member experience.Join For Free
In this article, we will look at a MongoDB tutorial that explains how to set up and start with MongoDB in Windows Operating System.
MongoDB is a free, open-source, cross-platform, document-oriented, not a relational one, Schema-less, easy to use and scale out, powerful, NoSQL database. 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).
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 below-mentioned steps.
You can find the Version and Architecture of Operating System in two ways:
1. Go to “This PC”, and the 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 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 don’t want to install complete package or wants to change the default installation location).
Select checkbox in case if you want to install 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 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 Edit Button.
Add new path variable and 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 database 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 MongoD command runs successfully, open another command prompt and run Mongo command. It will connect you to mongo shell on your localhost with default port 27017.
Use db command in order to check your current selected database.
Hope this will help you.
Published at DZone with permission of Anoop Kumar Sharma , DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.