Docs 菜单

atlas api

公开预览版:请在 < https:// 反馈 .mongodb.com/forums/930808 -atlas-cli > 提供反馈:使用Atlas CLI访问Atlas Administration API的所有功能,语法如下: ' atlas api '.<tag><operationId>

公开预览版中的此功能允许您使用Atlas CLI直接与任何Atlas Administration API端点交互,从而简化了脚本开发。

有关Atlas Administration API 的更多信息,请参阅:https://www.mongodb.com/zh-cn/docs/atlas/reference/api-resources-spec/v2/- Atlas Administration API入门:https://www.mongodb.com/zh-cn/docs/atlas/configure-api-access/#std-label-atlas-admin-api-access

公开预览版中的此功能允许您使用Atlas CLI直接与任何Atlas Administration API端点交互,从而简化了脚本开发。

命令语法
atlas api <tag> <operationId> [options]

重要

<tag><operationId> 都必须采用驼峰命名法。

名称
类型
必需
说明

<tag>

字符串

true

Atlas Administration API操作的类别,采用 camelCase 格式。要查找并格式化标签,请查看端点的API文档URL 。它显示在 #tag/ 之后,但需要更改为 camelCase。有关Atlas API文档,请参阅:https://www.mongodb.com/zh-cn/docs/atlas/reference/api-resources-spec/v2 /。

示例,在 https://www.mongodb.com/zh-cn/docs/atlas/reference/api-resources-spec/v2/#tag/Monitoring-and-Logs 中,标签为 Monitoring-and-Logs。在驼峰命名法中,它是 monitoringAndLogs

<operationId>

字符串

true

Atlas Administration API端点的标识符,采用驼峰命名法。要查找 operationId,请检查端点的API文档URL 。它出现在 operation/ 之后。有关Atlas API文档,请参阅:https://www.mongodb.com/zh-cn/docs/atlas/reference/api-resources-spec/v2 /。

示例,在 https://www.mongodb.com/zh-cn/docs/atlas/reference/api-resources-spec/v2/#tag/Clusters/operation/listClusters 中,operationId 为 listClusters

将Atlas Administration API端点的路径和查询参数作为标志传入。示例,如果端点为 /api/atlas/v2/orgs/{orgId}/invoices/{invoiceId},则Atlas CLI命令为:

atlas api <tag> <operationId> --orgId <ORG_ID> --invoiceId <INVOICE_ID>

注意

您通常不需要指定 --orgId--projectId,因为它们源自您的配置文件。仅当您的配置文件中未设立这些内容时才指定它们。

如果适用于端点,请使用 --file 选项或标准输入 (stdin) 传入请求正文。示例:

atlas api clusters create --file cluster-config.json

此外,以下选项可用于所有Atlas Administration API端点。

名称
类型
必需
说明

--api-version

字符串

false

指定命令的Atlas Administration API版本。默认为最新API版本或您在配置文件中为 api_version 配置的值。

--out

字符串

false

输出格式。默认值为 json,但支持的格式可能因端点而异:

  • 大多数端点输出 json。当 json 受支持时,您还可以使用Go模板。

  • 某些端点支持jsoncsv,允许您使用 jsoncsv 或Go模板。

  • 某些端点输出二进制数据(示例gzip 格式的日志),需要使用 --out 选项。

要确定端点支持的格式,请执行以下操作:

-o, --out-file

字符串

false

保存输出的文件路径。默认下,结果显示在终端中。

--file

字符串

false

请求正文内容的文件路径(如果操作需要)。或者,通过标准输入 (stdin) 提供输入。

-h, --help

布尔

false

当前命令的帮助。

名称
类型
必需
说明

-h,--help

false

API帮助

名称
类型
必需
说明

-P, --profile

字符串

false

要从配置文件中使用的配置文件的名称。 要了解 Atlas CLI 的配置文件,请参阅 https://dochub.mongodb.org/core/atlas-cli-save-connection-settings。