Install, setup and start MongoDB on Windows

This post will provide the full path from downloading required binary archive/package for particular Windows version to starting up MongoDB in various ways

We will go through following high level steps-

  • Download the MongoDB binary archive for windows platform
  • Extract MongoDB archive
  • Setup up configuration parameters and start/stop MongoDB
    • using command line
    • using windows services

Download the MongoDB binary archive

For Windows platform, MongoDB distributes zip archive. Go to following downloads page from browser

Depends on system architecture, it comes in two distribution as

  • 32-bit
  • 64-bit

Downloading the 64-bit is recommended. Again, MongoDB distribution for Windows 64-bit ships with two flavors

  • one for Newer OS, Windows server 2008 and Windows 7, Server 2012 (download link Big Green button)
  • other for Older OS, Windows Server 2003,2008 and Vista (Download link, 64-bit legacy )

This distinction for x64 is made based on newer OS features which helps in enhanced performance of MongoDB.



After you download, you will get zip archive in follwing format-



Extract MongoDB archive

Once we have MongoDB archive, go ahead and extract archive using any zip extract program.

After extracting, you will get the directories inside archive as follows

here , bin directory contains the binaries in form of executables , such as mongod.exe, mongo.exe, monogexport.exe etc.


Setup up configuration parameters and start/stop MongoDB

For starting and stopping the MongoDB server, we need only the bin/mongod.exe, which is the daemon process executable for MongoDB. In short, it is the executable which starts up the MongoDB Server.

For starting up, we need to provide the parameters for executable, which i call it here as config parameters or params.

We can setup the config parameters using the two ways

  • Using command line options or
  • Using config file

Using command line options

With use of these command line options, we configure mongo daemon process. Basically, there lots of options we can specify but i will  give only those which required for this tutorial.

Following are some of them-

–dbpath : the existent directory path, which is required to store data files. this is most important option we need to specify, Note that, the directory path you are providing should exists otherwise process won’t start. If this path contains spaces then put all its path in double qoutes. e.g. –dbpath “c:\Program Files”

–logpath : the existent file path, used by mongo daemon process,for flush out loggs instead of in standard console. If this path contains spaces then put all its path in double qoutes

–port :  port no. where mongod process listen for connection from client, it defaults to 27017 if not specified

Note : While using the command prompt on some Windows OS like windows 7 or Windows server 2008, Run it with administrator privileges as shown as follows

Use the following commands to start the server process

Change to bin directory

cd I:\Servers\mongodb\bin

now type following command to start the mongod process

mongod --dbpath I:\Servers\data --port 27017

While starting, Windows firewall may block the process as shown as follows

Click “Allow access“ to proceed. After successful execution of command , it will show logging info in standard console itself  as shown follows

$> mongod --dbpath I:\Servers\data --port 27017

Tue Apr 09 22:49:13 [initandlisten] MongoDB starting : pid=4380 port=27017 dbpath=I:\Servers\data 64-bit host=Myi-PC

Tue Apr 09 22:49:13 [initandlisten] db version v2.2.1, pdfile version 4.5

Tue Apr 09 22:49:13 [initandlisten] git version: d6764bf8dfe0685521b8bc7b98fd1fab8cfeb5ae

Tue Apr 09 22:49:13 [initandlisten] build info: windows sys.getwindowsversion(major=6, minor=1, build=7601, platform=2, service_pack='Service Pack 1')


Tue Apr 09 22:49:13 [initandlisten] options: { dbpath: "I:\Servers\data", port: 27017 }

Tue Apr 09 22:49:13 [initandlisten] journal dir=I:/Servers/data/journal

Tue Apr 09 22:49:13 [initandlisten] recover : no journal files present, no recovery needed

Tue Apr 09 22:49:13 [initandlisten] waiting for connections on port 27017

Tue Apr 09 22:49:13 [websvr] admin web console waiting for connections on port 28017</em>

If you specify the logpath option, then logging will direct to that log file instead of showing up on standard console

$> mongod --dbpath I:\Servers\data --port 27017 --logpath I:\Servers\logs\mongod.log
all output going to: I:\Servers\logs\mongod.log

and prompt will wait there and you can find all the logs at specified log file location You can stop this process with use of  keys Ctrl+C  or  Ctrl +D from keyboard

Using the config file

Instead of specifying command line option, we can specify same with use of file, which i call it here as config file Config file is just text file, containing the parameters in the key=value form and each one is specified on the every line of file In this, we basically provide path to file (which contains the configurations) as command line option as “-f” or “–config” Following is the snippet for the config file

#This is an example config file for MongoDB
dbpath = I:\Servers\mongodb\data
port = 27017
logpath = I:\Servers\mongodb\logs\mongo.log

You can save this file with any extension, but specify full path with extension, while stating process as shown in following commands. From command prompt, you will use either of following

mongod -f I:\Servers\mongodb\config\mongodb.conf
mongod --config I:\Servers\mongodb\config\mongodb.conf
view raw hosted with ❤ by GitHub

Start/Stop MongoDB using the Windows services

Support for installing MongoDB as Windows service comes out of the box.

MongoDB daemon executable provides amazing support for the installation of services using few command line parameters without using additional components for this purpose Just we need set the few command line params and we are way to go.

Following are required parameters

–install : command line switch to install the service

–remove : command line switch to remove the service

–serviceName :  the name for mongod windows service and must adhere to naming services in windows like only accepting the alphanumeric chars with no spaces

–serviceDisplayName : Display name for service that is shown in services console, put this in double quotes if contains the spaces

–serviceDescription   : Small description about service, put this in double quotes if contains the spaces

While installing as service we must provide log file path as counterpart to starting it from command line, because while starting service we don’t as standard console

I will be using the config file for some configurations

# note that following should go only in only one line
$> mongod -f "I:\Servers\mongodb\config\mongodb.conf"
--install --serviceName mdb27017
--serviceDisplayName "MongoDB Server Instance 27017"
--serviceDescription "MongoDB Server Instance running on 27017"


In log path specified, you can check for the whether windows services started or not

Above will install the mongodb as Windows service, check Services console using services.msc

Now we can start or stop MongoDB using Windows services console as shown above.

For removing installed service use following

# note that following should go only in only one line
mongod -f "I:\Servers\mongodb\config\mongodb.conf"
--remove --serviceName mdb27017
--serviceDisplayName "MongoDB Server Instance 27017"
--serviceDescription "MongoDB Server Instance running on 27017"



14 thoughts on “Install, setup and start MongoDB on Windows

Add yours

  1. Does this connection persist after a windows shut-down? is it possible to add these flags to the main mongodb.exe?

  2. this is just awesome..i searched all over the web but this post was the most useful…. thanks a looootttt…..

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Blog at

Up ↑

%d bloggers like this: