Docs Home / mongosh / Snippets / Reference

Configuration Options配置选项

Warning

Experimental feature实验特性

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

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. For more details about how a particular snippet works, see the documentation for that snippet.这些选项控制mongosh和跟踪单个代码段包的包管理器之间的交互。有关特定代码段如何工作的更多详细信息,请参阅该代码段的文档。

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 File

A semi-colon (;) separated list of one or more URLs. Each URL links to metadata about available snippets. See multiple source URLs.一个以分号(;)分隔的一个或多个URL列表。每个URL都链接到有关可用代码段的元数据。查看多个源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.通过添加一个URL到snippetIndexSourceURLs,为敏感代码段配置第二个私有注册表。

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. Unset this value then restart mongosh to disable snippets.片段功能需要一个索引源URL才能运行。取消设置此值,然后重新启动mongosh以禁用代码段。

config.set('snippetIndexSourceURLs', '')

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

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