[1] Creating Directorys and files
Create a
configuration file and a
directory path for MongoDB
log Output ( logpath): First, you will manually create a new Windows service: Create the address of the log file:
MD "C:\Program Files\mongodb\log"
at the command prompt, create a configuration file for LogPath:
Echo LogPath =c:\program files\mongodb\log\ Mongo.log > "C:\Program files\mongodb\ mongod.cfg "--install
[2] running MongoDB service Official information:
1. Configure directories and files.
Create A configuration file and a directory path fo
R MongoDB Log output (logpath):Create A specific directory for MongoDB log files:
MD "C:\Program Files\mongodb\log"
in the
Command Prompt, create a configuration file for the logpath option for MongoDB:
echo Logpath=c:\program files\mongodb\log\mongo.log > "C:\Program files\mongodb\mongod.cfg"
2. Run the MongoDB service.Run All of the following commands in
Command Prompt with
"Administrative privileges:" Install the MongoDB service. For
--install to succeed, you
must specify the logpath run-time option.
"C:\Program files\mongodb\bin\mongod.exe"--config "C:\Program files\mongodb\mongod.cfg"--install
3. Stop or remove the MongoDB service as needed.
To stop the MongoDB service with the following command:
net stop MongoDB
To remove the MongoDB service use the following command:
"C:\Program Files\mongodb\bin\mongod.exe"--remove
"Official Information"manually Create a Windows Service for MongoDB
The following procedure assumes you has installed MongoDB using the MSI installer, with the default path C:\Program F ILES\MONGODB 2.6Standard.
If you have installed in a alternative directory, you'll need to adjust the paths as appropriate.
1Open an Administrator command prompt.Windows 7/vista/server (and R2)
Presses Win + R, then type cmd, then press Ctrl + Shift + Enter.
Windows 8
Press Win + X, then press A.
Execute the remaining steps from the Administrator command prompt.
2Create directories.
Create directories for your database and log files:
mkdir C:\data\dbmkdir C:\data\log
3Create a configuration file.
Create a configuration file. This file can include any of the configuration options for Mongod, butmust include a valid sett ing for logpath:
The following creates a configuration file, specifying both the LogPath and the dbpath settings in the C Onfiguration file:
echo logpath=c:\data\log\mongod.log> "C:\Program files\mongodb 2.6 standard\mongod.cfg" Echo dbpath=c:\data\db> > "C:\Program files\mongodb 2.6 standard\mongod.cfg"
4Create the MongoDB service.
Create the MongoDB service.
Sc.exe create MongoDB binpath= "\" C:\Program files\mongodb 2.6 standard\bin\mongod.exe\ "--service--config=\" c \ Program Files\mongodb 2.6 standard\mongod.cfg\ "" displayname= "MongoDB 2.6 standard" start= "Auto"
Sc.exe requires a space between "=" and the configuration values (eg "binpath="), and a "" to escape double quot Es.
If successfully created, the following log message would display:
[SC] CreateService SUCCESS
5Start the MongoDB service.
net start MongoDB
6Stop or remove the MongoDB service as needed.
To stop the MongoDB service, use the following command:
net stop MongoDB
To remove the MongoDB service, first stop the service and then run the following command:
Sc.exe Delete MongoDB
Configuring the Windows service for MongoDB