Modify Log Retention Duration
On this page
You can modify how long MongoDB Shell log files are retained. A log cleanup process automatically deletes log files older than the specified retention period. By default, log files are retained for 30 days.
About this Task
You can specify multiple criteria for log retention. For example, you can specify a maximum duration for log files of 60 days and a maximum log storage size of 2GB. Logs are deleted when any retention criterion is met, starting with the oldest logs.
Before you Begin
To check the current log retention duration, run the following command:
config.get("logRetentionDays")
Steps
To modify how long log files are retained, set the logRetentionDays
configuration option. You can set configuration options in the
configuration API or a configuration file.
Modify Log Duration with the Configuration API
The following command uses the config API to set log retention to 60 days:
config.set("logRetentionDays", 60)
Setting "logRetentionDays" has been changed
Modify Log Duration with a Configuration File
The following configuration file sets log retention to 60 days:
mongosh: logRetentionDays: 60
Disable Duration-Based Log Cleanup
To instruct MongoDB Shell to not delete logs based on file age, set
logRetentionDays
to Infinity
. You can perform this action
through the config API or configuration file. For example:
config.set("logRetentionDays", Infinity)
Important
To prevent log storage from growing too large, always specify at least one log retention criterion.