MongoDB Enterprise and Community packages ship with a configuration file that sets the default directories for data and logging. This configuration file is loaded by default when you start mongod as a service.
Considerations
User Permissions
By default on Linux, MongoDB runs using the mongod user account. If you change the user that runs the MongoDB process, you must also modify the permissions to the data and log directories to give this user access to these directories.
Configuration File
Official MongoDB packages include a configuration file.
These settings, such as the data directory and log directory specifications, take effect upon startup. That is, if you change the configuration file while the MongoDB instance is running, you must restart the instance for the changes to take effect.
Default Directories
Select your operating system to view the default directories for MongoDB.
Packages that install MongoDB on Linux-based operating systems place the configuration file at /etc/mongod.conf. When you start MongoDB through systemd, it automatically loads this configuration.
Data Directory
The configuration file sets the data directory to different paths, depending on your distribution:
Distributions | Path |
|---|---|
RHEL, SUSE, and Amazon Linux |
|
Debian and Ubuntu |
|
To change this default:
Update the
storage.dbPathsetting in the configuration file to change the data directory used by the service.
Log Directory
The configuration file sets the log directory to /var/log/mongodb. To change this default:
Update the
systemLog.pathsetting in the configuration file to change the log directory used by the service.
Packages that install MongoDB on Windows place the configuration file at <install directory>\bin\mongod.cfg. When you start MongoDB as a Windows service, the service automatically loads this configuration.
Data Directory
The configuration file sets the data directory to C:\Program Files\MongoDB\Server\9.1\data. To change this default:
Update the
storage.dbPathsetting in the configuration file to change the data directory used by the service.
Log Directory
The configuration file sets the log directory to C:\Program Files\MongoDB\Server\9.1\log\mongod.log. To change this default:
Update the
systemLog.pathsetting in the configuration file to change the log directory used by the service.
Formulae that install MongoDB on macOS using Homebrew use a configuration file. When you start MongoDB as a Homebrew service, it automatically loads this configuration.
The specific default paths used by MongoDB depend on whether you installed the Homebrew formulae on an Apple Silicon- or Intel-based macOS system.
The configuration file is at /opt/homebrew/etc/mongod.conf.
The configuration file is at /usr/local/etc/mongod.conf.
Data Directory
The default data directory is /opt/homebrew/var/mongodb.
The default data directory is /usr/local/var/mongodb.
To change this default:
Update the
storage.dbPathsetting in the configuration file to change the data directory used by the service.
Log Directory
The default log directory is /opt/homebrew/var/log/mongodb.
The default log directory is /usr/local/var/log/mongodb.
To change this default:
Update the
systemLog.pathsetting in the configuration file to change the log directory used by the service.