Docs HomeMongoDB Shell

Registries and Registry Configuration注册表和注册表配置

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存储库中打开此项目的问题。

This page discusses different registries and how to configure your system to use them.本页讨论了不同的注册表以及如何配置系统以使用它们。

Types of Registry Configuration注册表配置的类型

The snippets feature uses the npm package manager to install snippets from a pre-specified registry. snippets功能使用npm包管理器从预先指定的注册表中安装snippets。You can configure your local mongosh to use one or more registries:您可以将本地mongosh配置为使用一个或多个注册表:

  • The community registry that is maintained by MongoDBMongoDB维护的社区注册表
  • A private registry that you maintain您维护的私人注册表
  • Multiple registries used together多个注册表一起使用

Using the MongoDB Registry使用MongoDB注册表

This is a public, community registry that is maintained by MongoDB.这是一个由MongoDB维护的公共社区注册表

The community registry is the default registry. 社区注册表是默认注册表。It provides several useful snippets which can help you to get started. 它提供了几个有用的片段,可以帮助您入门。The snippets in the community registry are also good examples to use when you are ready to create your own snippets.当您准备创建自己的代码段时,社区注册表中的代码段也是很好的示例

MongoDB users are encouraged to contribute to this public registry. 鼓励MongoDB用户为这个公共注册表做出贡献。To learn how to share your code with other MongoDB users, see Contribute a Snippet Package to the MongoDB Community.要了解如何与其他MongoDB用户共享代码,请参阅向MongoDB社区贡献Snippet包

Using Private Snippet Registries使用专用代码段注册表

You can share code internally using a private registry.您可以使用专用注册表在内部共享代码。

If your snippets reveal proprietary or sensitive information, you can store them in a private, local registry instead of the public registry.如果您的代码片段显示专有或敏感信息,您可以将它们存储在私有的本地注册表中,而不是公共注册表中。

To create a private registry, see Define a New Registry.要创建专用注册表,请参阅定义新注册表

Using Multiple Registries使用多个注册表

A private registry can also be used in conjunction with the community registry and other private registries. 私人登记处也可以与社区登记处和其他私人登记处结合使用。Using multiple registries allows you to benefit from snippets maintained by MongoDB or third parties while also maintaining control over code you don't want to share externally.通过使用多个注册表,您可以从MongoDB或第三方维护的代码片段中获益,同时还可以控制不想在外部共享的代码。

To configure multiple registries, see Connecting to Registries.要配置多个注册表,请参阅连接到注册表

How to Configure a Registry如何配置注册表

To use a private registry or multiple registries:要使用专用注册表或多个注册表:

Define a New Registry定义新注册表

The npm public registry hosts the MongoDB snippets community registry. npm公共注册表托管MongoDB snippets社区注册表。You can use npm to host your own public or private registry as well.您也可以使用npm来托管您自己的公共或私人注册表。

1

Create A GitHub Repository.创建GitHub存储库。

You will push snippet packages from your GitHub repository to your npm registry.您将把代码片段包从GitHub存储库推送到npm注册表。

Follow the GitHub documentation to create a repository.按照GitHub文档创建存储库。

2

Create An npm Registry.创建一个npm注册表。

Follow the npm registry documentation to create a registry.按照npm注册表文档创建注册表。

3

Update snippetIndexSourceURLs.更新snippetIndexSourceURL

To make the new registry available to your local mongosh installation, update the snippetIndexSourceURLs configuration settings.要使新注册表可用于本地mongosh安装,请更新snippetIndexSourceURLs配置设置。

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

Update snippetRegistryURL.更新snippetRegistryURL

If you created a registry that is hosted outside npm, update snippetRegistryURL to point to the new registry.如果您创建的注册表托管在npm之外,请更新snippetRegistryURL以指向新注册表。

Connecting to Registries正在连接到注册表

You can use a private registry in addition to, or instead of, the community MongoDB registry.您可以在社区MongoDB注册表之外使用私有注册表,也可以使用私有注册表来代替。

snippetIndexSourceURLs ia a list of URLs. ia URL列表。Each URL defines a path to an index file that contains metadata for the snippets in that registry.每个URL都定义了一个指向索引文件的路径,该索引文件包含该注册表中代码段的元数据。

Configure an additional registry by adding a URL to snippetIndexSourceURLs.通过向snippetIndexSourceURL添加URL来配置附加注册表。

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

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

Important

If two snippets with the same name appear in multiple registries, local system updates will be based on the entry in the first registry in the snippetIndexSourceURLs list.如果两个具有相同名称的代码段出现在多个注册表中,则本地系统更新将基于snippetIndexSourceURL列表中第一个注册表中的条目。

Do not reuse snippet names to avoid potential conflicts.不要重复使用代码段名称以避免潜在的冲突。