文档菜单
文档首页
/
MongoDB Shell
/ /

手动创建索引文件注册表

警告

实验性功能

此功能为实验性。MongoDB不提供代码片段的支持。此功能可能会在任何时候无事先通知的情况下更改或删除。

预期不会出现错误,但如果您遇到错误,请在GitHub 仓库 用于此项目。

本页讨论了如何手动创建注册表索引文件。要使用脚本生成注册表索引文件,请参阅创建注册表索引文件.

要创建注册表索引文件

  1. 复制以下 TypeScript 模板,并保存为make-index.ts:

    import bson from 'bson';
    import zlib from 'zlib';
    interface ErrorMatcher {
    // Add additional information to shell errors matching one of the regular.
    // expressions. The message can point to a snippet helping solve that error.
    matches: RegExp[];
    message: string;
    }
    interface SnippetDescription {
    // The *npm* package name. Users do not interact with this.
    name: string;
    // The snippet name. This is what users interact with.
    snippetName: string;
    // An optional install specifier that can be used to point npm towards
    // packages that are not uploaded to the registry. For example,
    // this could be an URL to a git repository or a tarball.
    installSpec?: string;
    // A version field. Users do not interact with this, as currently, `snippet`
    // always installs the latest versions of snippets.
    version: string;
    description: string;
    readme: string;
    // License should be a SPDX license identifier.
    license: string;
    errorMatchers?: ErrorMatcher[];
    }
    interface SnippetIndexFile {
    // This must be 1 currently.
    indexFileVersion: 1;
    index: SnippetDescription[];
    metadata: { homepage: string };
    }
    const indexFileContents: SnippetIndexFile = {
    indexFileVersion: 1,
    index: [ /* ... */ ],
    metadata: { homepage: 'https://example.com' }
    };
    // Serialize, compress and store the index file:
    fs.writeFileSync('index.bson.br',
    zlib.brotliCompressSync(
    bson.serialize(indexFileContents)));
  2. 根据您的代码片段包需要编辑 make-index.ts。使用注释作为填写所需信息的指南。

  3. 运行 ts-node make-index.ts 以创建 index.bson.br 文件

  4. index.bson.br 上传到您的 GitHub 仓库。

  5. 更新 snippetIndexSourceURLs 以包含一个引用您的 index.bson.br 的 URL。

返回

错误处理器