Snippets代码段
On this page本页内容
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预计不会出现错误,但如果您遇到错误,请在GitHub存储库 for this project.
中打开此项目的问题。
Introduction介绍
A snippet
is a script that is packaged and stored in a registry to facilitate sharing and reuse.snippet
是一个脚本,它被打包并存储在注册表中,以便于共享和重用。
You can write your own scripts in 您可以在mongosh
to manipulate data or to perform administrative tasks. mongosh
中编写自己的脚本来操作数据或执行管理任务。Snippets are an improvement on locally stored scripts because they can be easily shared and maintained.代码段是对本地存储脚本的改进,因为它们可以很容易地共享和维护。
This page provides a high level introduction to working with snippets. 本页提供了使用代码段的高级介绍。The links in each section go deeper into writing, managing, and working with snippets.每一节中的链接都深入到编写、管理和使用片段。
Components组件
The Snippets feature has three main components:代码段功能有三个主要组件:
- Scripts
are code that can be used with是可以与mongosh
.mongosh
一起使用的代码。 - Packages
are scripts that are bundled with metadata so they can be managed more easily.是与元数据捆绑在一起的脚本,因此可以更轻松地管理它们。 - Registries
are collections of packages that can be shared.是可以共享的包的集合。
There are also built in commands to help you work with snippets and utility scripts to help with packaging tasks.还有一些内置命令可以帮助您使用代码段,还有一些实用程序脚本可以帮助打包任务。
Get Started开始
The fastest way to get started with snippets is to try one of the snippets in the community registry开始使用代码段的最快方法是在MongoDB维护的社区注册表 maintained by MongoDB.
中尝试其中一个代码段。
You can also create your own snippets, package them for easier management, and configure a registry to share them.您还可以创建自己的代码段,将它们打包以便于管理,并配置注册表以共享它们。
Try an Existing Snippet.尝试现有代码段。Install and run a snippet package from the community registry从社区注册表安装并运行snippet包
Create Your Own Snippet Package.创建您自己的代码段包。Write the snippet code and supporting files.编写代码段和支持文件。Then, publish the snippet package.然后,发布snippet包。Configure Snippet Registries.配置代码段注册表。
Use the community registry使用社区注册表or configure a private registry.
或配置专用注册表。