How to install MongoDB on Windows as a Service

by Virender
July 29, 2015

When we working on MongoDB , We use console to run MongoDB. But some time we need MongoDB run as a services. In this tutorial I am giving details to run MongoDB as a Windows Services.

These are steps to run MongoDB as a Services

  1. Download MongoDB
  2. Create/Move MongoDB Folder
  3. Check MongoDB Folder
  4. Create Data Folder for MongoDB
  5. Create MongoDB Log File
  6. Configure MongoDB Configuration File ” mongod.cfg”
  7. Install MongoDB as a Service
  8. Start MongoDB Service
  9. Check MongoDB on Services Window
  10. Connect to MongoDB
  11. Stop MongoDB Service
  12. Delete MongoDB Service

Note :- If you got “Access is denied” to run any command , You must run command line as “Administrator”

1. Download MongoDB

First of all you need to download MongoDB from MongoDB website.

MongoDB Support on

Mac OS X

For windows we have two options download MSI file or compressed (tgz/zip) file.

2. Create/Move MongoDB Folder

MSI File  – If you downloaded .msi file then MongoDB will be install MongoDB into Program Files Or Program Files (x86) depend upon 32 bits or 64 bits.

After then you need to move MongoDB folder into c: drive (Note – I am using C: drive you can use any drive ). MongoDB not depend on any other files so it will not create any problem to move .

tgz/zip File – If you download compressed file then create MongoDB folder into c: and extract files into MongoDB folder.

3. Check MongoDB Folder

MongoDB’s bin Folder contains many executable files. Like mongo , mongoD etc. Every executable have different task.

4. Create Data Folder for MongoDB

MongoDB need (Data Directory) For run MongoDB . For that we need to create Data folder where database files create by MongoDB. I am using “data” folder inside bin folder for Data Directory.

5. Create MongoDB Log File

For run MongoDB as a Services we need first create log file. Because MongoDB services require log file to run MongoDB as a services. In log file we can check log like service started time , services stop time , problem on MongoDB server etc. It’s very useful for troubleshoot problem.

For create “mongod.log” file inside log folder in bin folder
binlogmongod.log” then create ” mongod.log”  file inside log folder

6. Create MongoDB configuration file

Create configuration file “mongo.config” inside bin folder its plain text file. mongo.config file contains path of Data Directory and Log File. The reason is that MongoDB Services need Data Directory and Log file to read/write. mongo.config only contains absolute path.

mongo.config sample

destination: file
path: C:MongoDBServer3.0binlogmongod.log
dbPath: C:MongoDBServer3.0bindata

7. Install MongoDB as Windows Service

We configure everything need to run MongoDB as a Windows Services. Now create a Window services by using sc.exe.

Run following command

C:>sc.exe create MongoDB binPath=”C:MongoDBServer3.0binmongod –service —
config=”C:MongoDBServer3.0binmongod.cfg”” DisplayName=”MongoDB” start=”au

Note – 

binPath – Path of executable file of mongod (mongod.exe).

config= Path of mongod.cfg file.

DisplayName –  Name which need to show on services window.

start- Its startup Type . You can set it demand/ auto/ delayed-auto etc.

8. Start MongoDB Service

Now start MongoDB Services. Use following command on console to start MongoDB Service.

net start MongoDB
sc start MongoDB

9. Check MongoDB on Services Window

10.  Connect to MongoDB

10. Stop MongoDB Service

net stop MongoDB
sc stop MongoDB

11. Delete MongoDB Service

sc delete MongoDB

Need a help , connect with us on skype



Notify of
Newest Most Voted
Inline Feedbacks
View all comments
3 years ago

Please solve this

3 years ago

[sc] startservice FAILED 1053:

3 years ago

Having a problem of this service did not respond to the start or control request in a timely fashion

Related posts