MongoDB

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.

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

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.

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.

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: