MongoDB Environment Setup | Install MongoDB on Windows

1. Objective

In previous MongoDB Tutorial, we discussed the advantages and limitations of MongoDB. In this MongoDB Environment setup Tutorial, we will see how to set up the environment for MongoDB on your Windows OS. Also, we will learn how to install MongoDB.

So, let’s the MongoDB Environment Setup/Install MongoDB.

MongoDB Environment Setup | Install MongoDB on Windows

MongoDB Environment Setup | Install MongoDB on Windows

2. Steps for MongoDB Environment Setup on Windows

MongoDB Environment Setup is very easy for Windows OS. To do environment setup, you will have to follow few simple steps.

  1. Know your Windows architecture
  2. Download MongoDB setup file
  3. Install MongoDB setup
  4. Set up MongoDB Environment
  5. Connect to the MongoDB server
  6. MongoDB as a Windows service
  7. Create configuration file
  8. Run MongoDB Environment setup

Before moving let’s discuss what is MongoDB in detail

a. Know your Windows Architecture

Before downloading MongoDB setup, you must know which Windows version you are using. To know about your system architecture, open the command prompt and execute some commands given below.

MongoDB Environment Setup | Install MongoDB

Image.1 MongoDB Environment Setup – Know your Windows Architecture

After executing these commands, you will know if your system is running on 32-bit or 64-bit architecture. Then you have to download the MongoDB setup accordingly.

b. Download MongoDB Setup File

After knowing the architecture, you have to download the latest version of MongoDB from the official website.

MongoDB Environment Setup

Image.2 MongoDB Environment Setup – Download MongoDB Setup File

You can follow this link to download from community server of MongoDB.

ttps://www.mongodb.org/downloads

Download the MSI file from this server.

MongoDB Environment Setup | Install MongoDB

Image 3. Download MongoDB Setup File

c. Install MongoDB Setup

To install MongoDB setup, you need to run the file as administrator. After doing that you need to follow the setup guide that appears in the installation process.

MongoDB Environment Setup | Install MongoDB

Image. 4 MongoDB Environment Setup – Install MongoDB Setup

Do you know How MongoDB Create Database?

MongoDB Environment Setup | Install MongoDB

Image. 5 MongoDB Environment Setup – Install MongoDB Setup

You can choose a custom directory for the MongoDB data and log files. Otherwise, by default, it will install MongoDB to C:\Program Files\MongoDB\Server\3.6\.

Read About MongoDB Features in detail

MongoDB does not have any system dependency, so it is not problematic to choose any folder in the directory. You can choose any directory in the system.

MongoDB Environment Setup | Install MongoDB

Image. 6 MongoDB Environment Setup – Install MongoDB Setup

You will see the option to install MongoDB compass in addition to MongoDB serve and you can check the box if you want it to install MongoDB. If not, leave it blank.

MongoDB Environment Setup | Install MongoDB

Image. 7 MongoDB Environment Setup – Install MongoDB Setup

 

MongoDB Environment Setup | Install MongoDB

Image. 8 MongoDB Environment Setup – Install MongoDB Setup

Let’s Discuss How MongoDB Create and Drop Collection

d. MongoDB Environment Setup

All of MongoDB data is stored in a specified data directory. You need to create it manually in the MongoDB Folder on the C drive. For this, run the following command at the command prompt.

 md \data\db 

You can install MongoDB at any location of your choice. 

MongoDB Environment Setup | Install MongoDB

Image. 9 MongoDB Environment Setup 

e. Start MongoDB

To start MongoDB you need to execute this command. This will start the main MongoDB process. You will see at the bottom of the command prompt a message as “waiting for a connection”. This means that the process has started successfully.

“C:\Program Files\MongoDB\Server\3.6\bin\mongod.exe”

MongoDB Environment Setup | Install MongoDB

Image. 10 MongoDB Environment Setup – Start MongoDB

f. Connect to MongoDB Server

After executing the MongoDB.exe file, the process has begun. Now we need to connect it to the MongoDB server. We will connect it through Mongo.exe shell by opening another command prompt. Now you need to execute a command to connect with the shell. 

“C:\Program Files\MongoDB\Server\3.6\bin\mongo.exe”

Now MongoDB is ready to use. You can terminate the running Process of MongoDB by pressing “ctrl+c”.

MongoDB Environment Setup | Install MongoDB

Image 11. MongoDB Environment Setup – Connect to MongoDB Server

Do you know What is MongoDB CRUD?

g. MongoDB as a Windows Service

Now you need to create some directories using command prompt & executing the following commands:

mkdir c:\data\db

mkdir c:\data\log 

Also, you can directly create new folders on the c drive. First, create a folder and name it “data” then create two folders as “db” and “log” inside the data folder. All of your database and the log files will be stored in these two folders.

MongoDB Environment Setup | Install MongoDB

Image 11. MongoDB Environment Setup – MongoDB as a Windows Service

h. Create a MongoDB Configuration File

After creating directories, you need to create a configuration file. The file must specify both the systemLog.path and storage.dbPath. Otherwise, an error will be shown on the display and service will not be able to start.

systemLog:
    destination: file
    path: c:\data\log\mongod.log
storage:
    dbPath: c:\data\db 

i.  Create the MongoDB Service

You need to execute this command for creating the MongoDB service

sc.exe create MongoDB binPath= “\”C:\Program Files\MongoDB\Server\3.6\bin\mongod.exe\” –service –config=\”C:\Program Files\MongoDB\Server\3.6\mongod.cfg\”” DisplayName= “MongoDB” start= “auto” 

If the service is successfully created the following message will display 

[SC] CreateService SUCCESS 

j. Start the MongoDB Service

If you want to start the service, you have to write a single sentence in a command prompt.
net start MongoDB.

Also, Read – MongoDB Data Modelling with Document Structure

k. Stop the Service

Similarly, to stop the service you have to execute the following command.
net stop MongoDB

l. Remove the Service

You can delete the service whenever you want by executing this simple code. 
net stop MongoDB 
This will first stop the service then delete it from the system.

This was all about MongoDB Environmental Setup Tutorial. Hope you like our explanation of How to Install MongoDB on Windows 10.

3. Conclusion

Hence, we saw MongoDB Environment Setup. Also, we learn how to run it as a Windows service. It was all about downloading the setup and writing some code lines in the command prompt. Furthermore, if you have any query, feel free to ask in a comment section.

Related Topic – MongoDB Indexing

For reference 

Leave a Reply

Your email address will not be published. Required fields are marked *