Docs Menu
Docs Home
/
MongoDB Shell
/ / /

Modify Log Retention Duration

On this page

  • About this Task
  • Before you Begin
  • Steps

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.

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.

To check the current log retention duration, run the following command:

config.get("logRetentionDays")

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.

The following command uses the config API to set log retention to 60 days:

config.set("logRetentionDays", 60)
Setting "logRetentionDays" has been changed

The following configuration file sets log retention to 60 days:

mongosh:
logRetentionDays: 60

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.

Back

Retention