Install MongoDB as service in Windows

By default MongoDB in Windows runs as a process. If the user running the application logs out, the database process will exit. To prevent this, you can run the mongodb database as a service.

Install FileCloud

Before making MongoDB as a service, install FileCloud using the windows installer. By default FileCloud will be installed under C:\xampp. If you have manually installed FileCloud or installed FileCloud on a different path, update the paths accordingly in the next steps.

Make MongoDB run as Windows Service



Alternate Installation Method Step 1: Create MongoDB Config File

Update a file called mongodb.conf under C:\xampp\mongodb\bin, and use absolute paths for the locations of logpath and dbpath to be absolute paths.

It is important when running mongodb as a service that the dbpath and the logpath are provided as full paths instead of relative paths. ie c:\xampp\mongodb\bin\data

Mongodb configuration file
# mongodb.conf

# Where to store the data.
dbpath=C:\xampp\mongodb\bin\data

#where to log
logpath=C:\xampp\mongodb\bin\log\mongodb.log

#append log
logappend=true

#ip address
bind_ip = 127.0.0.1
port = 27017

# Enable journaling, http://www.mongodb.org/display/DOCS/Journaling
journal=true

# Don't show mongodb http interface
nohttpinterface=true

# Enable mongodb rest interface
rest=false
 
#quiet mode
quiet=true

Here update values of logpath and dbpath if necessary.

Alternate Installation Method Step 2: Create MongoDB Service

To install MongoDB as a service, open a command prompt with administrator access (this is important), and run the following command.

Creating MongoDB Service
C:\> cd C:\xampp\mongodb\bin
C:\xampp\mongodb\bin> mongod.exe --config C:\xampp\mongodb\bin\mongodb.conf --install

You can start the MongoDB service using the FileCloud Control Panel.
Now the service will start automatically on machine reboots.

Remove MongoDB Service

Removing MongoDB Service
C:\xampp\mongodb\bin>mongod.exe --remove