Category: Database

How to run the MongoDB as a Windows Service

Making logs and data folders:

1) Open command prompt in administrative mode
2) md F:\mongodb\log
3) md F:\mongodb\data
4) md F:\mongodb\data\db

Creating config file and add logpath and dbpath in it:

1) echo logpath=F:\mongodb\log\mongo.log > F:\mongodb\mongod.cfg
2) dbpath=F:\mongodb\data\db [add this to the next line in mongod.cfg]

Installing the MongoDB service using the above config file [mongod.cfg]:

C:\>F:\mongodb\bin\mongod.exe –config F:\mongodb\mongod.cfg –install
all output going to: F:\mongodb\log\mongo.log
log file [F:\mongodb\log\mongo.log] exists; copied to temporary file [F:\mongodb\log\mongo.log.2013-11-16T18-26-32]

Run the MongoDB service:

C:\>net start MongoDB

The Mongo DB service was started successfully.

Stop the MongoDB service:

C:\>net stop MongoDB

Removing the MongoDB service:

C:\>F:\mongodb\bin\mongod.exe –remove