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.