对于 AI 代理:可在 https://www.mongodb.com/zh-cn/docs/llms.txt 获取文档索引—通过在任何 URL 路径后添加 .md 可获取所有页面的 Markdown 版本。
Docs 菜单

mongocli iam organizations apiKeys create

为您的组织创建 API 密钥。

MongoDB 仅返回私有 API 密钥一次。 运行此命令后,请立即复制、保存并保护公共和私有 API 密钥。

要使用此命令,您必须使用具有“组织用户管理员”角色的用户帐户或 API 密钥进行身份验证。

命令语法
mongocli iam organizations apiKeys create [options]
名称
类型
必需
说明

--desc

字符串

true

API 密钥的描述。

-h,--help

false

创建帮助

--orgId

字符串

false

要使用的组织 ID。 此选项会覆盖配置文件或环境变量中的设置。

-o, --output

字符串

false

输出格式。 有效值为 json、json-path、go-template 或 go-template-file。 要查看完整输出,请使用 -o json 选项。

--role

字符串

true

要分配给API密钥的一个或多个角色。 要分配多个角色,请为每个角色指定单独的角色标志,或使用一个角色标志将所有角色指定为以逗号分隔的列表。 要学习;了解CLI接受哪些值,请参阅Atlas API规范中角色的枚举项:https: //www.mongodb.com/zh-cn/docs/atlas/reference/api-resources-spec/v 2 /# 标签/ Programmatic- API-Keys/operation/createApiKey/。

名称
类型
必需
说明

-P, --profile

字符串

false

要从您的配置文件中使用的配置文件的名称。要学习;了解MongoCLI 的配置文件,请参阅 https://dochub.mongodb.org/core/atlas-cli-configuration-file.

如果命令成功,CLI 将返回类似于以下示例的输出。 括号中的值代表您的价值观。

API Key '<ID>' created.
Public API Key <PublicKey>
Private API Key <PrivateKey>
# Create an organization API key with organization owner access in the organization with the ID 5a1b39eec902201990f12345:
mongocli iam organizations apiKeys create --role ORG_OWNER --desc "My API Key" --orgId 5a1b39eec902201990f12345 --output json