Configure Settings Using a Configuration File使用配置文件配置设置
On this page本页内容
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. mongosh
配置文件使用YAML格式。All options are under the 所有选项都在mongosh
namespace.mongosh
命名空间下。
Example Configuration File配置文件示例
The following configuration file sets:以下配置文件集:
displayBatchSize
to 50为50inspectDepth
to为20redactHistory
to为remove-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 | mongosh
mongosh reads a configuration file in one of these directories, any remaining directories in the list are not checked and configuration files in those directories are ignored.mongosh 读取了其中一个目录中的配置文件,列表中的任何剩余目录都不会被检查,这些目录中的设置文件也会被忽略。 |
Linux | /etc/mongosh.conf |
Configurable Settings可配置设置
You can specify the following 您可以在配置文件中指定以下mongosh
settings in your configuration file:mongosh
设置:
displayBatchSize | integer | 20 | |
enableTelemetry | boolean | true | |
editor | string | null | mongosh console. mongosh 控制台中使用的编辑器。EDITOR environment variable if set.EDITOR 环境变量(如果已设置)。 |
forceDisableTelemetry | boolean | false | true ,则用户无法手动启用遥测。 |
historyLength | integer | 1000 | mongosh REPL's history file.mongosh REPL的历史文件中的项目数。 |
inspectCompact | integer or boolean | 3 | The level of inner elements that mongosh 在一行中输出的内部元素的级别。false , mongosh outputs each field on its own line.false ,mongosh 将在自己的行上输出每个字段。 |
inspectDepth | integer or Infinity | 6 | inspectDepth to Infinity (the javascript object) prints all nested objects to their full depth.inspectDepth 设置为Infinity (javascript对象)会将所有嵌套对象打印到其全部深度。 |
redactHistory | string | remove |
|
showStackTraces | boolean | false | |
snippetAutoload | boolean | true | true , automatically load installed snippets at startup.true ,则在启动时自动加载已安装的snippets。 |
snippetIndexSourceURLs | string | MongoDB Repository | |
snippetRegistryURL | string | npm Registry | mongosh npm client that installs snippet.mongosh npm客户端使用的npm注册表。 |
Behavior with config
APIconfig
API的行为
config
APISettings specified with the config API:使用配置API指定的设置:
Override settings specified in the configuration file.覆盖配置文件中指定的设置。Persist across restarts.在重新启动时坚持。
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。