mongod
Run the MongoDB database server
TLDR
Specify the storage directory (default: /data/db on Linux and macOS, C:\data\db on Windows)
Specify a configuration file
Specify the port to listen on (default: 27017)
Specify the database profiling level. 0 is off, 1 is only slow operations, 2 is all (default: 0)
SYNOPSIS
mongod [options]
PARAMETERS
--bind_ip
Specifies the IP address(es) on which the mongod instance listens for client connections. Comma-separated list.
--dbpath
Specifies the directory where the mongod instance stores its data.
--port
Specifies the TCP port for the mongod instance to listen on. Default: 27017.
--config
Specifies the path to a YAML or JSON configuration file.
--logpath
Specifies the path to the log file.
--fork
Runs the mongod instance as a background process.
--replSet
Specifies the name of the replica set.
--auth
Enables authentication.
--keyFile
Specifies the path to the key file for internal authentication.
--storageEngine
Specifies the storage engine to use (e.g., wiredTiger, mmapv1). Default: wiredTiger.
--verbose
Increases the amount of logging output. Can be specified multiple times.
--help
Displays help information.
--version
Displays version information.
DESCRIPTION
The mongod command starts the MongoDB database server. It manages data access, executes background operations, and listens for client connections.
mongod is the core process of a MongoDB deployment. Properly configuring mongod is critical for performance, security, and data integrity. It controls various aspects of MongoDB's operation, from storage engine selection and data directory location to network settings and authentication mechanisms.
Before running mongod, you'll typically need to configure it via a configuration file (usually named mongod.conf) or command-line options. These options specify the database path, port, security settings, replication options, and other server behaviors. Consider using `mongosh` command-line utility for interacting with the database. mongod process should run in background unless run for specific debugging.
CAVEATS
Running mongod requires sufficient system resources, including memory and disk space. Incorrect configuration can lead to data loss or security vulnerabilities. Always review the official MongoDB documentation for the most up-to-date information and best practices.
DATA DIRECTORY
The data directory (specified by `--dbpath`) must exist and be accessible to the user running mongod. It's crucial to ensure the directory has appropriate permissions to prevent unauthorized access or data corruption.
CONFIGURATION FILE
Using a configuration file (`--config`) is the recommended way to manage mongod settings. It allows you to define all server options in a single, easily manageable file, avoiding long and complex command-line arguments. The file must be in valid YAML or JSON format.
SECURITY CONSIDERATIONS
Enabling authentication (`--auth`) is essential for securing your MongoDB instance. You should also configure proper network settings (e.g., `--bind_ip`) to restrict access to authorized clients only. Using TLS/SSL encryption is crucial for protecting data in transit.
HISTORY
The mongod command originated with the initial release of MongoDB, designed to be a scalable and performant NoSQL database solution. Over time, it has undergone significant development, with improvements in storage engines, security features, and replication capabilities. Early versions relied heavily on command-line options, while more recent versions emphasize configuration files for easier management. The move to wiredTiger as the default storage engine was a major milestone in improving performance and concurrency. The evolution of mongod reflects the growing demands of modern applications for flexible and scalable data storage.