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

Run the MongoDB Service Manually

To start the MongoDB service manually, run the mongod process directly from the command line with the options and configuration you need.

mongod [options]
Task
Description

Start

To manually start the MongoDB process, run the mongod command.

Status

To manually check the status of a running MongoDB process, use the serverStatus command.

Stop

To manually stop the MongoDB process, run the mongod command with the --shutdown option or connect to the server and use the db.shutdownServer() method.

For the full list of options, see the mongod reference.

On self-managed deployments of MongoDB Enterprise and MongoDB Community installed on Linux-based or macOS operating systems, you can manually manage the MongoDB process through mongod, and other commands.

Note

Running MongoDB on Windows

On Windows, you manage MongoDB as a Windows Service rather than by running mongod directly. Windows does not support the --fork option. Register the service with mongod.exe rather than starting the process from the command line. To learn more, see Run the MongoDB Service on Windows.

When you manually start the MongoDB process, it executes as the user that runs the mongod command.

This user must have read and write access to the data and the log directories. If MongoDB runs as a user who does not have these privileges, it exits with an error.

Before you start the MongoDB process, ensure that the data and log directories exist. To create the /path/to/dataDir and /path/to/logs directories, run the following commands:

sudo mkdir -p /path/to/dataDir
sudo mkdir -p /path/to/logs

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.

For example:

storage:
dbPath: /path/to/dataDir
systemLog:
destination: file
path: /path/to/logs
logAppend: true
net:
port: 27017
bindIp: 127.0.0.1

The user MongoDB 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.

To start the mongod process, run the following command:

mongod --config /path/to/mongod.conf

On Linux-based operating systems, you can use the --fork option to start MongoDB as a background process.

To check the status of a running mongod 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 })
}

To stop the MongoDB process, run mongod with the --shutdown option, or connect to the server with mongosh and run the db.shutdownServer() method.

If you started mongod with a configuration file, you also need to use the --config option when shutting it down. This method only works on Linux-based operating systems.

mongod --config /path/to/mongod.conf --shutdown