Running MongoDB on Windows

2014, Jun 10    

MongoDbLogoI've been working with MonogDB lately. Getting it setup and running on a development box is easy, but I wanted to document the steps for reference.

Install MongoDB

Download MongoDB from their website. For windows, I prefer the 64-bit Zip file. The MSI installs into Program Files, but I prefer to keep the binaries and the databases together and not have to run as an Admin.

Extract the Zip file to c:\MongoDB

In the MongoDB directory, create a data subdirectory and in it add db and log subdirectories. The bin subdirectory should already be there. Your directory structure should now look like this,


Configure MongoDB

Add a text file called  c:\MongoDB\mongod.cfg that contains the following,

   destination: file
   path: c:\mongodb\data\log\mongodb.log
   logAppend: true
    dbPath: c:\mongodb\data\db
   port: 27017

This sets the log and the db path and also sets the port to the default so it is easy to change later. Notice that I am only binding to because my server is currently insecure so I do not want to expose it on the network. For more configuration options, see the documentation.

Test MongoDB

Now that I have it set up, it is time to test the installation. Start it at the command prompt like this,

C:\MongoDb\bin>mongod.exe -f ..\mongod.cfg

Then in another command window, connect to the running server to make sure it is up and running. I am shutting the server down while I am connected to it, thus the errors.

MongoDB shell version: 2.6.1
connecting to: test
> use admin
switched to db admin
> db.shutdownServer()
2014-06-10T14:28:35.567-0400 DBClientCursor::init call() failed
server should be down...
2014-06-10T14:28:35.571-0400 trying reconnect to ( failed
2014-06-10T14:28:36.579-0400 warning: Failed to connect to, reason: errno:10061 No connection could be made because the target machine actively refused it.
2014-06-10T14:28:36.579-0400 reconnect ( failed failed couldn't connect to server (, connection attempt failed
> exit

Install as a service

We now know that our configuration is correct, so now I want to install it as a service so that it is always running,

Start an Administrator command prompt. On Windows 7, press WIN+R, then type cmd, them press CTRL+SHIFT+ENTER. On Windows 8, press WIN+X, then press A.

Now run the command,

sc.exe create MongoDB binPath="C:\MongoDB\bin\mongod.exe --service --config=C:\MongoDB\mongod.cfg" DisplayName="MongoDB 2.6 Standard" start="auto"

You should then see,

[SC] CreateService SUCCESS

You can now start and stop the service with the following commands,

net start MongoDB
net stop MongoDB

If you ever want to uninstall the service, the command is,

sc.exe delete MongoDB

Next Steps

You now have a MongoDB development server running on your local system. It does not require authentication, but is not exposed on the network, only through When you are ready to deploy to production, you will need to set up security and replication.

For development in .NET you will want to start with the Official MongoDB C# driver NuGet package.