Quick Contact

    MongoDB Tutorial

    Mongo DB Environment Setup

    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
    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.

    Mongo DB Environment Setup

    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.

    Download MongoDB Setup File

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

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


    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.

    Mongo DB Environment Setup

    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.

    Mongo DB Environment Setup
    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.

    Mongo DB Environment Setup
    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”

    Mongo DB Environment Setup
    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”.

    Mongo DB Environment Setup
    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.

    Mongo DB Environment Setup
    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.

        destination: file
        path: c:\data\log\mongod.log
        dbPath: c:\data\db 
    Create the MongoDB Service

    You need to execute this command for creating the MongoDB service

    	sc.exe create MongoDBbinPath= “\”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

    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.

    Stop the Service

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

    net stop MongoDB

    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.

    Must Read About MongoDB Tutorial.

    Copyright 1999- Ducat Creative, All rights reserved.