Docs HomeMongoDB Shell

Configuration Options配置选项

Warning

Experimental feature实验特性

This feature is experimental. 此功能是实验性的。MongoDB does not provide support for Snippets. MongoDB不支持Snippets。This feature may be changed or removed at any time without prior notice.此功能可能随时更改或删除,恕不另行通知。

Bugs are not expected, however should you encounter one, please open an issue in the GitHub repository for this project.预计不会出现错误,但如果您遇到错误,请在GitHub存储库中打开此项目的问题。

These options control the interaction between mongosh and the package manager that tracks individual snippet packages. 这些选项控制mongosh和跟踪单个代码段包的包管理器之间的交互。For more details about how a particular snippet works, see the documentation for that snippet.有关特定代码段如何工作的更多详细信息,请参阅该代码段的文档。

To modify the snippet configuration settings, use the following method:要修改代码段配置设置,请使用以下方法:

config.set('<OPTION>', '<VALUE>')

Configuration Options配置选项

Option选项Type类型Default默认值Description描述
snippetAutoloadbooleantrueAutomatically load installed snippets at startup.启动时自动加载已安装的代码段。
snippetIndexSourceURLslistMongoDB Repository Index FileA semi-colon (;) separated list of one or more URLs. 一个或多个URL的以分号(;)分隔的列表。Each URL links to metadata about available snippets. 每个URL都链接到有关可用片段的元数据。See multiple source URLs.请参阅多个源URL
To disable snippets, unset this value. 若要禁用代码段,请取消设置此值。See an example.请参见示例
snippetRegistryURLstringMongoDB npm RegistryThe npm registry that the mongosh npm client uses to install snippetsmongosh npm客户端用于安装代码段的npm注册表

Update the configuration options using the config command, then restart mongosh for the updates to take effect.使用config命令更新配置选项,然后重新启动mongosh以使更新生效。

Examples示例

Add a Second Registry添加第二个注册表

Configure a second, private registry for sensitive snippets by adding a URL to snippetIndexSourceURLs.通过向snippetIndexSourceURL添加URL,为敏感代码段配置第二个专用注册表。

config.set('snippetIndexSourceURLs',
'https://github.com/YOUR_COMPANY/PATH_TO_YOUR_REGISTRY/index.bson.br;'
+ config.get('snippetIndexSourceURLs')
)

Restart mongosh for the update to take effect.重新启动mongosh以使更新生效。

Disable Snippets禁用代码段

The snippets feature requires an index source URL to function. snippets功能需要一个索引源URL才能正常工作。Unset this value then restart mongosh to disable snippets.取消设置此值,然后重新启动mongosh以禁用代码段。

config.set('snippetIndexSourceURLs', '')

Snippets can also be disabled from outside mongosh. 也可以从mongosh外部禁用代码片段。If you cannot start mongosh because of a corrupt snippets configuration, disable snippets and restart mongosh.如果由于snippets配置损坏而无法启动mongosh,请禁用snippets并重新启动mongosh

mongosh --nodb --eval 'config.set("snippetIndexSourceURLs", "")'