I have been developing for MongoDB for some months now and would like to install it as a service on my Windows 7 Enterprise machine. The following is the command that I have executed to create the service:

"D:\Milvia Systems\Development\MongoDB\mongod.exe" --logpath "D:\Milvia Systems\Development\MongoDB\logs\DBLog.log" --logappend --dbpath "D:\Milvia Systems\Development\MongoDB\db" -vvv --reinstall

However, whenever I use net start "MongoDB" or the Service Control Panel I receive the following error:

Error 1053: The service did not respond to the start or control request in a timely fashion.

Environment: Windows 7 Enterprise 64bit MongoDB: 1.6.3 pdfile version 4.5

Solution 1

Have your checked you logging to see the real problem?

I suggest extracting the Mongo installation to c:\mongodb.

Create the c:\mongodb\logs and the c:\mongodb\data\db directories.

Then browse the the c:\mongodb\bin directory and run the following to remove the service (if you've installed it!):

mongod --remove

Then install the service, specifying the log and data directories:

mongod --logpath c:\mongodb\logs\mongo.log --dbpath c:\mongodb\data\db --directoryperdb --install

Then if there is a problem starting the service you should see the reason in the specified log file.

More info here.

Solution 2

If you did not specify absolute file paths for the data directory, or the log directory, you will get the same Windows error, but no log file.

I used the information from "Install MongoDB Service on Windows 7", pushed on Webiyo to correct the registered service arguments:

  1. Download MongoDB and extract it to the C:\ drive.
  2. Add "data" and "logs" subdirectories under the "C:\mongodb165" directory.
  3. Add a log file name "mongolog.txt" at "C:\mongodb165\logs\mongolog.txt".
  4. Change the directory to "C:\mongodb165\bin".
  5. Execute the following command:

    mongod --install --rest master logpath=C:\mongodb165\logs\mongolog.txt
  6. Open the registry editor (regedit.exe), go to HKEY_LOCAL_MACHINE SYSTEM CurrentControlSet Services.

  7. Find the MongoDB key and set the "ImagePath" value to:

    C:\mongodb165\bin\mongod --service  --rest  --master  --logpath=C:\mongodb165\logs\mongolog.txt  --dbpath=C:\mongodb165\data
  8. Save the changes to the registry and exit the registry editor.

  9. Open ComponentServices, click on "Services (Local)", and find the MongoDB service. Start it.
  10. Check at the URL http://localhost:28017/ to verify that MongoDB returns stats.

Solution 3

I just encountered the same issue on my windows 7 machine. I followed the directions in MongoDBs Docs for the install, but it wouldn't let me execute "net start MongoDB" unless I was in "C:\". I didn't want to go back and reinstall MongoDB to follow the instructions included in the Webiyo link referenced above though. If you already installed MongoDB according to their docs and want to be able to execute "net start MongoDB" from where ever your project directory is:

Go to HKEY_LOCAL_MACHINE > SYSTEM > CurrentControlSet > services > MongoDB

Double click ImagePath under the Name column

Paste in the following ImagePath ( edit the folder directory and names to match your needs ):

C:\mongodb\bin\mongod.exe --service  --rest  --master  --logpath=C:\mongodb\log\mongolog.txt  --dbpath=C:\mongodb\data\db --config C:\mongodb\mongod.cfg

Note that if you direct copy this ImagePath value and your "data" folder is in the mongodb directory instead of C:\ add the following line to your "mongod.cfg" file: dbpath=C:\mongodb\data\db

After I did this, when I run "net stop MongoDB" I get the message "System error 109 has occurred. The pipe has been ended." You may see it as well. This message has been discussed thoroughly at

To save you the time of reading the whole back and forth discussion, Tad Marshalls post sums up this issue:

"... it was working fine in 2.1.0; later changes broke it again. But yes, you get this error message in the current code.

The explanation is that mongod.exe is exiting from a callback thread created by the Windows Service Control Manager when it calls us due to "net stop mongodb" and this breaks the RPC pipe it used to create the callback thread. We need to reorganize our exit logic to avoid doing this.

The error message is the only real effect of this issue; we exit on command, cleanly, and inform the Windows Service Control Manager that we are stopped, but then the "net" command displays an error message because we didn't return from the RPC call the way it expected us to."

Solution 4

My mongod.cfg file had the following last two lines:


I have no idea why there's an mp: in there. But when I manually executed the image path

C:\mongodb\bin\mongod.exe --config "C:\mongodb\bin\mongod.cfg" --service



I got

c:\mongodb\bin>mongod /?C:\mongodb\bin\mongod.exe --config "C:\mongodb\bin\mongod.cfg" --service
Unrecognized option: mp
try 'mongod --help' for more information

So I commented it out and then the service started without any problem.

Solution 5

These are the steps I followed to install mongoDB on windows 7

  1. download the .msi file from the mongodb site--> and run it

  2. Wherever your mondoDb is downloaded (generally in the c drive Program Files folder), go to that folder and wherever is the bin folder in that same folder create your data folder and your log folder

3.Inside your data folder create your db folder

The structure would look something like this

  1. Now open command prompt as administrator.

  2. change your file path and enter the bin folder.( in this case it would be c>program files>MongoDB>bin> )

  3. Type in the following command : mongod --directoryperdb --dbpath "C:/Program Files\MongoDB\data" --logpath "C:\Program Files\MongoDB\log\mongo.log" --logappend --rest --install

  4. This would set the logpath and database path. Lastly run net start MongoDB . Hope this helps.

Solution 6

I ran this command:

C:\MongoDB\Server\3.4\bin>net start MongoDB

And got this message:

The service is not responding to the control function. More help is available by typing NET HELPMSG 2186.

After some trials and errors, I noticed when following the tutorial it asked me to name my file mongod.conf but the command was trying to refer to mongod.cfg.

As soon as I corrected that name and re-run the commands,

C:\MongoDB\Server\3.4\bin>sc.exe delete MongoDB
[SC] DeleteService SUCCESS

C:\MongoDB\Server\3.4\bin>sc.exe create MongoDB binPath= "\"C:\MongoDB\Server\3.4\bin\mongod.exe\" --service --config=\"C:\MongoDB\Server\3.4\mongod.cfg\"" DisplayName= "MongoDB" start= "auto"
[SC] CreateService SUCCESS

C:\MongoDB\Server\3.4\bin>net start MongoDB
The MongoDB service is starting....
The MongoDB service was started successfully.

The service started running fine.

Solution 7

To others who may have the same problem on Windows Server 2012:

I have just got the same problem with Mongo 3.0.3 on Windows Server 2012. I am not a system admin so I don't know what they have changed for sc.exe. I have to use

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

This is without the \"\" for both binary and config file paths comparing to the one on their website.

Solution 8

For mongoDB 3.0, You will have to set the following in the config file.


the logpath should end with a file and not a folder.

Solution 9

Check if your mongod.cfg file has tabs in it. Removing tabs solved it for me!

Solution 10

Following works with MongoDB 3.6.0

Make sure you have these folders:

  • C:\mongodb\data
  • C:\mongodb\data\db

Then all you need are these commands:

  • mongod --directoryperdb -dbpath C:\mongodb\data\db --logpath C:\mongodb\log\mongo.log --logappend --service --install
  • net start MongoDB
  • mongo

Solution 11

Another way this might fail is if the account running the service doesn't have write permission into the data directory.

In that case the service will be unable to create a lock file.

The mongod service behaves badly in this situation and goes into a loop starting a process, which immediately throws an unhandled exception, crashes, etc. the log file gets recreated every time the process starts up, so you have to grab it quick if you want to see the error.

the default user for windows services would be localhost\system. so the fix is to ensure this user can write into your db directory, or start the service as another user who can.

Solution 12

For version 2.6 at least, you must create the /data/db/ and /log/ folders that the mongo.cfg points to. MongoDB won't do so itself, and will throw that error in response when ran as a service.

Solution 13

make sure to open the command line with "run as administrator" rights in the right click before typing the entire mongod things

Solution 14

Just try to run mongod.exe locally in command line, you can get here exception, that mongod calls and try to solve it. In my case it was small free space on local disc, so I just change location of directories and change Mongocofig file and now it run ok.

Solution 15

After spend half an hour on debug ... I finally found that there is single dash before the "rest" attribute.

Solution 16

If you look in the service details, you can see that the command to start the service is something like:

"C:\Program Files\MongoDB\bin\mongod" --config  C:\Program Files\MongoDB\mongod.cfg  --service 

The MongoDB team forgot to add the " around the --config option. So just edit the registry to correct it and it will work.

Solution 17

I had same issue on windows 8.1

The solution which worked for me is to specify config file path correctly

Going to HKEY_LOCAL_MACHINE > SYSTEM > CurrentControlSet > services > MongoDB > imagePath the value was like the following:

"C:\Program Files\MongoDB 2.6 Standard\bin\mongod.exe" --config mongod.cfg --service

Then just I corrected config file path to match my actual path:

"C:\Program Files\MongoDB 2.6 Standard\bin\mongod.exe" --config "d:\mongodb\mongod.cfg" --service

Solution 18

Remember to create the database before starting the service

C:\>"C:\Program Files\MongoDB\Server\3.2\bin\mongod.exe" --dbpath d:\MONGODB\DB
2016-10-13T18:18:23.135+0200 I CONTROL  [main] Hotfix KB2731284 or later update is installed, no need to zero-out data files
2016-10-13T18:18:23.147+0200 I CONTROL  [initandlisten] MongoDB starting : pid=4024 port=27017 dbpath=d:\MONGODB\DB 64-bit host=mongosvr
2016-10-13T18:18:23.148+0200 I CONTROL  [initandlisten] targetMinOS: Windows 7/Windows Server 2008 R2
2016-10-13T18:18:23.149+0200 I CONTROL  [initandlisten] db version v3.2.8
2016-10-13T18:18:23.149+0200 I CONTROL  [initandlisten] git version: ed70e33130c977bda0024c125b56d159573dbaf0
2016-10-13T18:18:23.150+0200 I CONTROL  [initandlisten] OpenSSL version: OpenSSL 1.0.1p-fips 9 Jul 2015
2016-10-13T18:18:23.151+0200 I CONTROL  [initandlisten] allocator: tcmalloc
2016-10-13T18:18:23.151+0200 I CONTROL  [initandlisten] modules: none
2016-10-13T18:18:23.152+0200 I CONTROL  [initandlisten] build environment:
2016-10-13T18:18:23.152+0200 I CONTROL  [initandlisten]     distmod: 2008plus-ssl
2016-10-13T18:18:23.153+0200 I CONTROL  [initandlisten]     distarch: x86_64
2016-10-13T18:18:23.153+0200 I CONTROL  [initandlisten]     target_arch: x86_64
2016-10-13T18:18:23.154+0200 I CONTROL  [initandlisten] options: { storage: { dbPath: "d:\MONGODB\DB" } }
2016-10-13T18:18:23.166+0200 I STORAGE  [initandlisten] wiredtiger_open config: create,cache_size=8G,session_max=20000,eviction=(threads_max=4),config_base=false,statistics=(fast),log=(enabled=true,archive=true,path=journal,compressor=snappy),file_manager=(close_idle_time=100000),checkpoint=(wait=60,log_size=2GB),statistics_log=(wait=0),
2016-10-13T18:18:23.722+0200 I NETWORK  [HostnameCanonicalizationWorker] Starting hostname canonicalization worker
2016-10-13T18:18:23.723+0200 I FTDC     [initandlisten] Initializing full-time diagnostic data capture with directory 'd:/MONGODB/DB/'
2016-10-13T18:18:23.895+0200 I NETWORK  [initandlisten] waiting for connections on port 27017

Then you can stop the process Control-C

2016-10-13T18:18:44.787+0200 I CONTROL  [thread1] Ctrl-C signal
2016-10-13T18:18:44.788+0200 I CONTROL  [consoleTerminate] got CTRL_C_EVENT, will terminate after current cmd ends
2016-10-13T18:18:44.789+0200 I FTDC     [consoleTerminate] Shutting down full-time diagnostic data capture
2016-10-13T18:18:44.792+0200 I CONTROL  [consoleTerminate] now exiting
2016-10-13T18:18:44.792+0200 I NETWORK  [consoleTerminate] shutdown: going to close listening sockets...
2016-10-13T18:18:44.793+0200 I NETWORK  [consoleTerminate] closing listening socket: 380
2016-10-13T18:18:44.793+0200 I NETWORK  [consoleTerminate] shutdown: going to flush diaglog...
2016-10-13T18:18:44.793+0200 I NETWORK  [consoleTerminate] shutdown: going to close sockets...
2016-10-13T18:18:44.795+0200 I STORAGE  [consoleTerminate] WiredTigerKVEngine shutting down
2016-10-13T18:18:45.116+0200 I STORAGE  [consoleTerminate] shutdown: removing fs lock...
2016-10-13T18:18:45.117+0200 I CONTROL  [consoleTerminate] dbexit:  rc: 12

Now your database is prepared and you can start the service using

C:\>net start MongoDB
The MongoDB service is starting.
The MongoDB service was started successfully.

Solution 19

Check if a process instance of mongod is already running. If yes, this service will not start because C:\data\db\mongod.lock will be used by it.

And to start MongoDB as a service, this file shall be not used by any process.

Solution 20

For me, the issue was the wrong directory. Make sure you copy paste the directory from your file explorer and not assume the directory specified on the docs page correct.

Solution 21

If you receive the error:

the service name is invalid

when running net start mongodb, you will need to run the following command from Step 4 of Manually Create a Windows Service for MongoDB Community Editition:

sc.exe create MongoDB binPath= "\"C:\Program Files\MongoDB\Server\3.4\bin\mongod.exe\" --service --config=\"C:\Program Files\MongoDB\Server\3.4\mongod.cfg\"" DisplayName= "MongoDB" start= "auto"

Solution 22

I had made few changes in the Config start-up file, which caused this issue. When I looked in the "mongo.log" file, it said

"Cannot start server. Detected data files in E:\Mongo\data\db created by storage engine 'wiredTiger'. The configured storage engine is 'mmapv1'., terminating"

Resetting the storage engine back to 'wiredTiger' resolved the issue for me. Hope this helps others.

Solution 23

I started following a tutorial on a blog that required MongoDB. It had instructions on downloading and configuring the service. But for some reason the command for starting the Windows service in that tutorial wasnt working. So I went to the MongoDB docs and tried running this command as listed in the

The command for strting mongodb service- sc.exe create MongoDB binPath= "\"C:\MongoDB\bin\mongod.exe\" --service --config=\"C:\MongoDB\bin\mongodb\mongod.cfg\"" DisplayName= "MongoDB" start= "auto"

I got this message: [SC] CreateService SUCCESS

Then I ran this one: net start MongoDB

And got this message:

The service is not responding to the control function.

More help is available by typing NET HELPMSG 2186.

I create a file named 'mongod.cfg' in the 'C:\MongoDB\bin\mongodb\' As soon as I added that file and re-ran the command- 'net start MongoDB', the service started running fine.

Hope this helps.

Solution 24

Well, in my case, I was running low disk space on my drive where I have my MongoDB data files. I checked MongoDB logs file which stated the following

2015-11-11T21:53:54.717+0500 E JOURNAL [initandlisten] Insufficient free space for journal files 2015-11-11T21:53:54.717+0500 I JOURNAL [initandlisten] Please make at least 3379MB available in C:\wamp\bin\mongodb\data\db\journal or use --smallfiles

All I had to do is clean up some space and fire up the service again.. Worked for me. So All you have to is check your logs file and deal with the problem accordingly.