MongoDB Enterprise and MongoDB Community are available to run on Windows as a Windows Service managed with the net command, through the mongod.exe command-line interface, or manually through the Services console.
Syntax
net <command> MongoDB
Right-click the MongoDB service in the Services console and select the operation you want to perform.
"C:\Program Files\MongoDB\Server\9.1\bin\mongod.exe" <opts>
Compatibility
On self-managed deployments of MongoDB Enterprise and MongoDB Community installed on Windows, you can manage the mongod process as a Windows Service.
For more information on supported platforms, see:
Behavior
User Privileges
Most commands that manage a Windows Service require elevated privileges. Open the Windows command prompt (cmd.exe) as an Administrator before you run these commands.
By default, the service runs in the context of a local system account. To run the service as a specific user, register it with the --serviceUser and --servicePassword options. That user must have the Log on as a service privilege.
Data Directory
Before you start the MongoDB process, ensure that the data directory exists. To create the default \data\db data directory, run the following commands from the Command Interpreter:
cd C:\ md "\data\db"
The default data directory path is the absolute path \data\db on the drive from which you start MongoDB.
Configuration File
You can configure the MongoDB process through command-line options or through a configuration file. If you plan to run MongoDB for a long period of time or need it to always run with specific options, use a configuration file.
If you installed MongoDB with the Windows installer, the installer creates a configuration file for you at C:\Program Files\MongoDB\Server\9.1\bin\mongod.cfg.
If you installed MongoDB from the ZIP archive, create the file yourself. For example:
storage: dbPath: C:\data\db systemLog: destination: file path: C:\data\log.txt logAppend: true net: port: 27017 bindIp: 127.0.0.1
The user the service runs as must have read access to the configuration file and read and write access to the dbPath and path directories.
Important
Set bindIp to 127.0.0.1 to restrict connections to the local machine. To accept remote connections, set bindIp to a private or internal network interface.
Secure the deployment before you bind to a publicly-accessible address. To learn more, see Security Checklist for Self-Managed Deployments.
Service Registration
The Windows installer registers the MongoDB service for you, and the service starts when the installation succeeds. The service also starts when the system boots.
If you installed MongoDB from the ZIP archive, you must register the service yourself with the --install option before you can manage it with the net command.
Examples
Register the MongoDB Service
To register mongod.exe as a Windows Service, run mongod.exe with the --install option. Pass the --config option to register the service with the configuration file it reads at startup:
"C:\Program Files\MongoDB\Server\9.1\bin\mongod.exe" --config "C:\Program Files\MongoDB\Server\9.1\bin\mongod.cfg" --install
The service stores the options you register it with. When you later start the service with net start MongoDB, it reads the configuration file you specified here.
You need to register the service only once. The Windows installer performs this step for you.
Start MongoDB
To start the MongoDB service, use one of the following methods:
net start MongoDB
Right-click the MongoDB service in the Services console and click Start.
"C:\Program Files\MongoDB\Server\9.1\bin\mongod.exe" --dbpath="C:\data\db"
This command runs mongod.exe in the foreground. The --fork option is not supported on Windows.
Verify MongoDB Is Running
If you started MongoDB as a Windows Service, query the service from the command prompt:
sc query MongoDB
The command returns the service details. The STATE field reads RUNNING when the service is running and STOPPED when it is not.
If you started MongoDB as a Windows Service, locate the MongoDB service in the Services console. You should see the service listed as Running in the Status column.
If you started MongoDB manually in the foreground, the Command Interpreter displays the following line when the database server is running correctly:
[initandlisten] waiting for connections
To show runtime information for the running mongod.exe process, use mongosh to run the serverStatus command:
mongosh --quiet --eval "db.runCommand( { serverStatus: 1, none: 1, mem: 1 } )"
{ host: 'example', version: '9.1.0', process: 'mongod', pid: Long('71115'), uptime: 61, uptimeMillis: Long('61213'), uptimeEstimate: Long('61'), localTime: ISODate('2026-10-02T16:57:13.762Z'), ok: 1, '$clusterTime': { clusterTime: Timestamp({ t: 1790960233, i: 1 }), signature: { hash: Binary.createFromBase64('AAAAAAAAAAAAAAAAAAAAAAAAAAA=', 0), keyId: Long('0') } }, operationTime: Timestamp({ t: 1790960233, i: 1 }) }
You can also view the log file to see the current status of your mongod.exe process. The log file is the path you set with the --logpath option.
Stop MongoDB
To stop the MongoDB service, use one of the following methods:
net stop MongoDB
Right-click the MongoDB service in the Services console and click Stop.
Connect to the server with mongosh and run the db.shutdownServer() method on the admin database:
mongosh admin --quiet --eval "db.shutdownServer()"
The --shutdown option is available only on Linux systems. If you started mongod.exe in the foreground, you can also press Ctrl + C in the Command Interpreter to shut down the process cleanly.
Restart MongoDB
To restart the MongoDB service, use one of the following methods:
net stop MongoDB net start MongoDB
Right-click the MongoDB service in the Services console and click Restart.
Connect to the server with mongosh and run the db.shutdownServer() method on the admin database. Then, use mongod.exe to start the server again:
mongosh admin --quiet --eval "db.shutdownServer()" "C:\Program Files\MongoDB\Server\9.1\bin\mongod.exe" --dbpath="C:\data\db"
Remove the MongoDB Service
To remove the MongoDB service, first stop the service, then run the following command:
sc delete MongoDB