Docs Menu
Docs Home
/
MongoDB Shell
/ / /

Modify Maximum Log Storage Size

On this page

  • About this Task
  • Before you Begin
  • Steps

You can specify a maximum combined storage size for MongoDB Shell log files. If the total size of all log files exceeds the maximum, log files are deleted until the combined size is below the threshold, starting with the oldest log files. By default, there is no maximum log storage size.

To specify a maximum log storage size, set the logRetentionGB configuration option. logRetentionGB can be any positive float value (including less than 1).

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 storage size of log files, check the size of the log folder. To see the current log folder, run the following command from the MongoDB Shell:

config.get('logLocation')

To check the current maximum log storage size, run the following command:

config.get("logRetentionGB")

To modify maximum log storage size, set the logRetentionGB configuration option. You can set configuration options in the configuration API or a configuration file.

The following command uses the config API to set the maximum log storage size to 3.5 GB:

config.set("logRetentionGB", 3.5)
Setting "logRetentionGB" has been changed

The following configuration file sets the maximum log storage size to 3.5 GB:

mongosh:
logRetentionGB: 3.5

To instruct the MongoDB Shell to not delete logs based on storage size, set logRetentionGB to Infinity. You can perform this action through the config API or configuration file. For example:

config.set("logRetentionGB", Infinity)

Important

To prevent log storage from growing too large, always specify at least one log retention criterion.

Back

Duration