[1] 建立directorys和filesmongodb
echo logpath=C:\Program Files\MongoDB\log\mongo.log> "C:\Program Files\MongoDB\mongod.cfg" --install
md "C:\Program Files\MongoDB\log"
echo logpath=C:\Program Files\MongoDB\log\mongo.log > "C:\Program Files\MongoDB\mongod.cfg"
"C:\Program Files\MongoDB\bin\mongod.exe" --config "C:\Program Files\MongoDB\mongod.cfg" --install
To stop the MongoDB service use the following command:app
net stop MongoDB
To remove the MongoDB service use the following command:ui
"C:\Program Files\MongoDB\bin\mongod.exe" --remove
The following procedure assumes you have installed MongoDB using the MSI installer, with the default path C:\Program Files\MongoDB 2.6 Standard.spa
If you have installed in an alternative directory, you will need to adjust the paths as appropriate.日誌
Press Win + R, then type cmd, then press Ctrl + Shift + Enter.code
Press Win + X, then press A.ci
Execute the remaining steps from the Administrator command prompt.rem
Create directories for your database and log files:get
mkdir c:\data\db mkdir c:\data\log
Create a configuration file. This file can include any of the configuration options for mongod, butmust include a valid setting for logpath:cmd
The following creates a configuration file, specifying both the logpath and the dbpath settings in the configuration 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"
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 quotes.
If successfully created, the following log message will display:
[SC] CreateService SUCCESS
net start MongoDB
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