For AI agents: a documentation index is available at https://www.mongodb.com/ko-kr/docs/llms.txt — markdown versions of all pages are available by appending .md to any URL path.
Docs Menu

Run the MongoDB Service on Windows

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.

net <command> MongoDB

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:

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.

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.

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.

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.

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.

To start the MongoDB service, use one of the following methods:

net start MongoDB

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.

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.

To stop the MongoDB service, use one of the following methods:

net stop MongoDB

To restart the MongoDB service, use one of the following methods:

net stop MongoDB
net start MongoDB

To remove the MongoDB service, first stop the service, then run the following command:

sc delete MongoDB