## Step 3: Run the MongoDB service. 

Important: 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:\mongodb\bin\mongod.exe" --config "C:\mongodb\mongod.cfg" --install 

Modify the path to the mongod.cfg file as needed. 

To use an alternate dbpath , specify the path in the configuration file (e.g. C:\mongodb\mongod.cfg ) or on the command line with the --dbpath option. 

If the dbpath directory does not exist, mongod.exe will not start. The default value for dbpath is \data\db . 

If needed, you can install services for multiple instances of mongod.exe or mongos.exe . Install each service with a unique --serviceName and --serviceDisplayName . Use multiple instances only when sufficient system resources exist and your system design requires it. 

## Step 4: Stop or remove the MongoDB service as needed. 

To stop the MongoDB service use the following command: 

net stop MongoDB 

To remove the MongoDB service use the following command: 

"C:\mongodb\bin\mongod.exe" --remove 

## Manually Create a Windows Service for MongoDB 

You can set up the MongoDB server as a Windows Service that starts automatically at boot time. 

The following procedure assumes you have installed MongoDB using the .msi installer with the path C:\mongodb\ . 

If you have installed in an alternative directory, you will need to adjust the paths as appropriate. 

## Step 1: Open an Administrator command prompt. 

Press the Win key, type cmd.exe , and press Ctrl + Shift + Enter to run the Command Prompt as Adminis- trator. 

Execute the remaining steps from the Administrator command prompt. 

## Step 2: Create directories. 

Create directories for your database and log files: 

mkdir c:\data\db mkdir c:\data\log 

