Configure Settings Using a Configuration File
On this page
You can specify mongosh
settings in a global configuration file.
When you specify settings in a configuration file, those settings are
applied at startup. After you create a configuration file, the settings
in the file take effect the next time you start mongosh
.
Configuration File Format
The mongosh
configuration file uses the YAML format. All options are
under the mongosh
namespace.
Example Configuration File
The following configuration file sets:
displayBatchSize
to 50inspectDepth
to 20redactHistory
toremove-redact
mongosh: displayBatchSize: 50 inspectDepth: 20 redactHistory: "remove-redact"
Configuration File Location
The file location where mongosh
looks for the configuration file
depends on your operating system:
Operating System | File Location |
---|---|
Windows |
|
macOS |
Once |
Linux |
|
Configurable Settings
You can specify the following mongosh
settings in your configuration
file:
Key | Type | Default | Description |
---|---|---|---|
| boolean |
| Specifies whether MongoDB Shell writes log entries. |
| integer | 20 | The number of items displayed per cursor iteration |
| boolean |
| Enables sending anonymized tracking and diagnostic data to MongoDB. |
| string |
| Designates an editor to use within the |
| boolean |
| Only available in the global configuration file. When true, users cannot enable telemetry manually. |
| integer | 1000 | The number of items to store in |
| integer or boolean | 3 | |
| integer or Infinity | 6 | The depth to which objects are printed. Setting |
| boolean | false | Specifies whether MongoDB Shell compresses log files. When this
value is |
| string | Depends on your operating system. See View Shell Logs. | Directory where MongoDB Shell writes log files. Specify an absolute filepath. See Specify Log File Location. |
| integer or Infinity | 100 | Maximum number of log files that the MongoDB Shell retains. After the MongoDB Shell reaches the maximum log file count, it starts deleting the oldest log files until the count is below the threshold. See Modify Maximum Log File Count. |
| integer or Infinity | 30 | Number of days that MongoDB Shell log files are retained. If this
value is set to |
| float or Infinity | Unset | Maximum amount of space in gigabytes used for MongoDB Shell logs. If the combined size of MongoDB Shell logs exceeds this value, log files are deleted starting with the oldest logs. If this value is set to |
| string |
| Controls what information is recorded in the shell history. Must be one of:
|
| boolean |
| Controls display of a stack trace along with error messages. |
| boolean |
| If |
| string | A semicolon-separated list of URLs that link to a snippet registry. | |
| string |
Behavior with config
API
Settings specified with the config API:
Override settings specified in the configuration file.
Persist across restarts.
Example
Consider the following configuration file that sets the
inspectDepth
setting to 20
:
mongosh: inspectDepth: 20
During your mongosh
session you run the following command to set
inspectDepth
to 10
:
config.set( "inspectDepth", 10 )
The value of inspectDepth
becomes 10
, and will remain 10
even when mongosh
is restarted.