Install MongoDB on Windows

Posted on 12th September 2016

This chapter explains how to install MongoDB on the latest versions of Windows Operating Systems.

There are three builds of MongoDB available for Windows - 64-bit, 32-bit and 64-bit Legacy. 64-bit build is the recommended version which can run on Windows Server 2008 R2, Windows 7 64-bit, Windos 10 and newer versions of Windows. 32-bit build have a limitation of 2GB data. 64 bit legacy build is intended for Windows Vista or Windows server 2003, 2008. The latest versions of MongoDB does not support Windows XP.

Installation Steps

1. Download

Download the MSI installer for the latest version of MongoDB supported by your version and architecture of Windows from the MongoDB downloads page - MongoDB Downloads Page. At the time of writing this article the stable version is 3.2.9 for Windows server 2008 R2 64 bit and later. To find the version and architecture of your Windows, open a command prompt and run the following commands

wmic os get caption
wmic os get osarchitecture

Double-click the .msi file to install.

Choose setup type - Complete or Custom.

MongoDB Install Setup Type

If you choose Complete, the installation will proceed and MongoDB will be installed in the default location
C:\Program files\MongoDB\Server\<<version>>\

MongoDB Install

If you choose Custom, you can select the features to install. You can select from Server, Client, Monitoring tools, Import/Export tools, Router and miscellaneous tools. Choosing Custom also allows you to change Install Location.

MongoDB Custom Install

Click Finish when prompted and exit the installer.

Alternatively, you may download the zip file containing the binaries and extract the zip file to a suitable location.

2. Create Data Directory

Create a data directory for MongoDB to store the data files. By default this directory should be DriveLetter:datadb where DriveLetter is the same drive where the MongoDB binaries exist. You could create the data directory in a different location in which case the new location has to be specified using --dbpath option with mongod.exe (explained in the next step).

c:\> mkdir c:\data\db

3. Run MongoDB as a standard program

You could run MongoDB as a standard program or as a service. To run as a standard program:
Open Windows command prompt or power shell and change directory to the location where you installed MongoDB.

cd C:\MongoDB\Server\3.2\

Change directory to bin folder which contains the MongoDB binaries

C:\MongoDB\Server\3.2> cd bin

Start MongoDB database process by running the command mongod.exe

C:\MongoDB\Server\3.2\bin> mongod.exe

2016-09-12T12:03:49.559+0100 I CONTROL  [initandlisten] MongoDB starting : pid=9456 port=27017 dbpath=C:\data\db\ 64-bit host=MY-PC
2016-09-12T12:03:49.562+0100 I CONTROL  [initandlisten] targetMinOS: Windows 7/Windows Server 2008 R2
2016-09-12T12:03:49.564+0100 I CONTROL  [initandlisten] db version v3.2.9
2016-09-12T12:03:49.565+0100 I CONTROL  [initandlisten] git version: 22ec9e93b40c85fc7cae7d56e7d6a02fd811088c
2016-09-12T12:03:49.567+0100 I CONTROL  [initandlisten] OpenSSL version: OpenSSL 1.0.1p-fips 9 Jul 2015
2016-09-12T12:03:49.569+0100 I CONTROL  [initandlisten] allocator: tcmalloc
2016-09-12T12:03:49.570+0100 I CONTROL  [initandlisten] modules: none
2016-09-12T12:03:49.571+0100 I CONTROL  [initandlisten] build environment:
2016-09-12T12:03:49.572+0100 I CONTROL  [initandlisten]     distmod: 2008plus-ssl
2016-09-12T12:03:49.574+0100 I CONTROL  [initandlisten]     distarch: x86_64
2016-09-12T12:03:49.575+0100 I CONTROL  [initandlisten]     target_arch: x86_64
2016-09-12T12:03:49.577+0100 I CONTROL  [initandlisten] options: {}
2016-09-12T12:03:49.617+0100 I STORAGE  [initandlisten] wiredtiger_open config: create,cache_size=8G,session_max=20000,eviction=(threads_max=4),config_base=false,statistics=(fast),log=(enabled=true,archive=true,path=journal,compressor=snappy),file_manager=(close_idle_time=100000),checkpoint=(wait=60,log_size=2GB),statistics_log=(wait=0),
2016-09-12T12:03:50.408+0100 I NETWORK  [HostnameCanonicalizationWorker] Starting hostname canonicalization worker
2016-09-12T12:03:50.408+0100 I FTDC     [initandlisten] Initializing full-time diagnostic data capture with directory 'C:/data/db/'
2016-09-12T12:03:50.613+0100 I NETWORK  [initandlisten] waiting for connections on port 27017

If you get a security alert window saying Windows Firewall has blocked some features, Select Private networks, such as my home or work network and click Allow access

The console output shows process id, port no, dbpath, host name, db version. etc..The last message tells you that the database process is waiting for connection on port 27017 which indicates the process started successfully.

If your data directory is different from the default /data/db you can specify the path using --dbpath option. For example if you want to store your data in the folder C:\MongoDB\Server\Data, the command is

mongod.exe  --dbpath C:\MongoDB\Server\Data

4. Stop MongoDB process

When MongoDB runs as a standard program the easiest way to stop is to press CTRL+C on the console window that it runs.

5. Run MongoDB as service

You can configure MongoDB to runs as a service so that it starts automatically every time your system boots up. To install MongoDB as a Windows service, Open an elevated command prompt ( Right-click command prompt and select Run as Administrator). Run the following command:

mongod.exe --install --logpath C:\MongoDB\Server\3.2\mongodb.log

Check the mongodb.log file for any errors.

Logpath option specifies the file that stores that logs.

To run the newly installed service issue the command

net start MongoDB
The MongoDB service was started successfully.

6. Stop and Remove MongoDB Service

You can stop MongoDB service with the command

net stop MongoDB

To remove the MongoDB service

mongod.exe --remove

Post a comment


Nothing the first to share wisdom.