The following are not correct, note the escaped quotes are required. The MongoDB service was started successfully. T09:39:29.310+0800 I CONTROL Service 'MongoDB' removedĭ:\apps\MongoDB\Server\4.0\bin>sc.exe create MongoDB binPath= "\"D:\apps\MongoDB\Server\4.0\bin\mongod.exe\" -service -config=\"D:\apps\MongoDB\Server\4.0\bin\mongod.cfg\""ĭ:\apps\MongoDB\Server\4.0\bin>net start mongodb
T09:39:29.309+0800 I CONTROL Trying to remove Windows service 'MongoDB' T09:39:29.305+0800 I CONTROL Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify -sslDisabledProtocols 'none' The MongoDB service was stopped successfully.ĭ:\apps\MongoDB\Server\4.0\bin>mongod -remove D:\apps\MongoDB\Server\4.0\bin>mongod -config D:\apps\MongoDB\Server\4.0\bin\mongod.cfg -installĭ:\apps\MongoDB\Server\4.0\bin>net stop mongodb Then I run either the two command to create the service. Path: D:\apps\MongoDB\Server\4.0\log\mongod.log In my case, I create the mongod.cfg beside the mongd.exe with the following contents. & $mongoDBPath\bin\mongod.exe -config $mongoDbConfigPath -install Remove-Item $unzippedFolderContent -recurse -force $destination.Copyhere($shellApp.namespace($zipFile).items())Ĭopy-Item "$unzippedFolderContent\*" $mongoDbPath -recurse
$destination = $shellApp.namespace($mongoDbPath) $shellApp = New-Object -com shell.application ::AppendAllText("$mongoDbConfigPath", "noprealloc=true`r`n")
::AppendAllText("$mongoDbConfigPath", "smallfiles=true`r`n") ::AppendAllText("$mongoDbConfigPath", "logpath=C:\MongoDB\log\mongo.log`r`n") ::AppendAllText("$mongoDbConfigPath", "dbpath=C:\MongoDB\data\db`r`n") Write-host "Seems you already installed MongoDB" If ((Test-Path -path $mongoDbPath) -eq $True) $mongoDbConfigPath = "$mongoDbPath\mongod.cfg" This PowerShell Script Downloads and Installs MongoDB as Windows Service: Set-ExecutionPolicy RemoteSigned (8) Finally, restart your machine with MongoDB running and it will still be running on restart (Do not start MongoDB via Control Panel > Services, use. If not, check your log file at C:\data\log\mongod.log for the reason for failure and fix it To double check open Control Panel > Services, ensure the status of the MongoDB service is 'Running' IMPORTANT: Even if this says 'The MongoDB service was started successfully' it can fail sc.exe create MongoDB binPath= "\"C:\Program Files\MongoDB\Server\3.4\bin\mongod.exe\" -service -config=\"C:\data\mongod.cfg\"" DisplayName= "MongoDB" start= "auto" (6) To create service that will auto start on reboot. (5) Create c:\data\mongod.cfg with contents.
START THE SERVICE AUTOMATICALLY ON SYSTEM REBOOT / RESTART MongoDB Install Windows + FullyQualifiedErrorId : CouldNotStartService, + CategoryInfo : OpenError: (:ServiceController) , Or this: Start-Service : Service 'MongoDB (MongoDB)' cannot be started due to the following error: Cannot open MongoDB service net start MongoDB or Start-Service MongoDB in PowerShell), you'll get a response like this: System error 5 has occurred. (5)Īnd if you try to start the service from a non-admin console, (i.e. T15:24:54.618-0800 I CONTROL Error connecting to the Service Control Manager: Access is denied. If you don't do this, your log file ('D:\mongodb\log.txt' in the above example) will contain lines like these: T15:24:54.618-0800 I CONTROL Trying to install Windows service 'MongoDB' NOTE: Make sure to run command prompt as administrator. Then I executed this command after opening command prompt as administrator: D:\mongodb\bin>mongod -dbpath=D:\mongodb -logpath=D:\mongodb\log.txt -installĪfter that right there in the command prompt execute: services.mscĪnd look for MongoDB service and click start. Make sure that you added the \bin directory to the system variable PATHįirst I executed this command: D:\mongodb\bin>mongod -remove After trying for several hours, I finally did it.