Docs HomeMongoDB Shell

Snippets代码段

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

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 maintained by MongoDB.开始使用代码段的最快方法是在MongoDB维护的社区注册表中尝试其中一个代码段。

You can also create your own snippets, package them for easier management, and configure a registry to share them.您还可以创建自己的代码段,将它们打包以便于管理,并配置注册表以共享它们。