Docs Home / mongosh

Snippets代码片段

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

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. Snippets are an improvement on locally stored scripts because they can be easily shared and maintained.您可以用mongosh编写自己的脚本来操纵数据或执行管理任务。代码段是对本地存储脚本的改进,因为它们可以很容易地共享和维护。

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.您还可以创建自己的代码段,将其打包以便于管理,并配置注册表以共享它们。