Cannot start MongoDB as a service

后端 未结 24 1486
情话喂你
情话喂你 2020-12-07 10:07

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 hav

相关标签:
24条回答
  • 2020-12-07 10:16

    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"
    
    0 讨论(0)
  • 2020-12-07 10: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
    
    0 讨论(0)
  • 2020-12-07 10:18

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

    #snmp:
    mp:
    

    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
    

    at

    Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\MongoDB
    

    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.

    0 讨论(0)
  • 2020-12-07 10:18

    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.

    0 讨论(0)
  • 2020-12-07 10:18

    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.

    0 讨论(0)
  • 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.

    0 讨论(0)
提交回复
热议问题