You can specify 您可以在全局配置文件中指定mongosh settings in a global configuration file. mongosh设置。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.mongosh时生效。
Configuration File Format配置文件格式
The mongosh configuration file uses the YAML format. All options are under the mongosh namespace.mongosh配置文件使用YAML格式。所有选项都在mongosh名称空间下。
Example Configuration File配置文件示例
The following configuration file sets:以下配置文件集:
displayBatchSizeto 50inspectDepthto 20redactHistorytoremove-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:mongosh查找配置文件的文件位置取决于操作系统:
| Windows | mongosh.cfg, in the same directory as the mongosh.exe binary.mongosh.cfg,与mongosh.exe二进制文件位于同一目录中。 |
| macOS |
|
| Linux | /etc/mongosh.conf |
Configurable Settings可配置设置
You can specify the following 您可以在配置文件中指定以下mongosh settings in your configuration file:mongosh设置:
browser | string or boolean | System default browser |
|
disableLogging | boolean | false | |
disableSchemaSampling | boolean | false |
|
displayBatchSize | integer | 20 | |
enableTelemetry | boolean | true | |
editor | string | null | mongosh console. Overrides the EDITOR environment variable if set.mongosh控制台中使用的编辑器。如果已设置,则覆盖EDITOR环境变量。 |
forceDisableTelemetry | boolean | false | |
historyLength | integer | 1000 | mongosh REPL's history file.mongosh REPL历史文件中的项目数。 |
inspectCompact | integer or boolean | 3 |
|
inspectDepth | integer or Infinity | 6 | inspectDepth to Infinity (the javascript object) prints all nested objects to their full depth.inspectDepth设置为Infinity(javascript对象)会将所有嵌套对象打印到其完整深度。 |
logCompressionEnabled | boolean | false | true, MongoDB Shell uses gzip to compress logs. |
logLocation | string | 请参阅查看Shell日志。 | |
logMaxFileCount | integer or Infinity | 100 | |
logRetentionDays | integer or Infinity | 30 | Infinity, log files are not deleted based on age. To prevent log storage from growing too large, always specify at least one log retention criterion. |
logRetentionGB | float or Infinity | Unset |
|
oidcRedirectUri | string | http://localhost:27097/redirect | http://localhost:27097/redirect.http://localhost:27097/redirect。 |
oidcTrustedEndpoints | array of strings | [] (empty array) | localhost. localhost。 |
redactHistory | string | remove |
|
showStackTraces | boolean | false | |
snippetAutoload | boolean | true | true, automatically load installed snippets at startup.true,则在启动时自动加载已安装的代码段。 |
snippetIndexSourceURLs | string | MongoDB Repository | |
snippetRegistryURL | string | npm Registry | mongosh npm client that installs snippet.mongosh npm客户端使用的npm注册表。 |
Behavior with config API配置API时的行为
Settings specified with the config API:使用配置API指定的设置:
Override settings specified in the configuration file.覆盖配置文件中指定的设置。Persist across restarts.在重启过程中保持不变。
Example示例
Consider the following configuration file that sets the 考虑以下将inspectDepth setting to 20:inspectDepth设置设置为20的配置文件:
mongosh:
inspectDepth: 20
During your 在mongosh session you run the following command to set inspectDepth to 10:mongosh会话期间,运行以下命令将inspectDepth设置为10:
config.set( "inspectDepth", 10 )
The value of inspectDepth becomes 10, and will remain 10 even when mongosh is restarted.inspectDepth的值变为10,即使重新启动mongosh,它也将保持10。