MongoDB as service on Windows

Quick install script for installing mongodb a service on Windows. Further instructions are available in official MongoDB docs.

Download appropriate version: http://www.mongodb.org/downloads
extract to your folder of choice, startup cmd.exe as Administrator and change to the MongDB folder.

REM -- Setup directories
set mongodir=%PROGRAMDATA%\mongodb
mkdir %mongodir%
mkdir %mongodir%\data
mongod.exe --dbpath %mongodir%\data --logpath %mongodir%\log.txt --install
REM -- Read the logfile, check install was ok
type %mongodir%\log.txt
REM -- Start the service
net start mongodb

If you run into “System error 193 has occurred. *** is not a valid Win32 application.” -error when starting the service, there is probably some error in the mongod.exe command line. The command like you use here is used when installing the service (you can check it via Windows Service Manager). For example omitting the .exe -extension or having some extra spaces in dir names can cause these problems.