After trying for several hours, I finally did it.
Make sure that you added the <MONGODB_PATH>in
directory to the system variable PATH
First I executed this command:
D:mongodbin>mongod --remove
Then I executed this command after opening command prompt as administrator:
D:mongodbin>mongod --dbpath=D:mongodb --logpath=D:mongodblog.txt --install
After that right there in the command prompt execute:
services.msc
And look for MongoDB service and click start.
NOTE: Make sure to run command prompt as administrator.
If you don't do this, your log file (D:mongodblog.txt
in the above example) will contain lines like these:
2016-11-11T15:24:54.618-0800 I CONTROL [main] Trying to install Windows service 'MongoDB'
2016-11-11T15:24:54.618-0800 I CONTROL [main] Error connecting to the Service Control Manager: Access is denied. (5)
and if you try to start the service from a non-admin console, (i.e. net start MongoDB
or Start-Service MongoDB
in PowerShell), you'll get a response like this:
System error 5 has occurred.
Access is denied.
or this:
Start-Service : Service 'MongoDB (MongoDB)' cannot be started due to the following error: Cannot open MongoDB service
on computer '.'.
At line:1 char:1
+ Start-Service MongoDB
+ ~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OpenError: (System.ServiceProcess.ServiceController:ServiceController) [Start-Service],
ServiceCommandException
+ FullyQualifiedErrorId : CouldNotStartService,Microsoft.PowerShell.Commands.StartServiceComman
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…