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

mongocli iam projects apiKeys create

本页内容

  • 语法
  • 选项
  • 继承选项
  • 输出
  • 示例

创建一个组织API密钥并将其分配给您的项目。

MongoDB 只会返回一次私有 API 密钥。运行此命令后,请立即复制、保存并安全保管公钥和私钥。

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

命令语法
mongocli iam projects apiKeys create [options]
名称
类型
必需
描述
--desc
string
true
API 密钥的描述。
-h, --help
false
create 命令的帮助信息
-o, --output
string
false
输出格式。有效值包括 json、json-path、go-template 或 go-template-file。要查看完整输出,请使用 -o json 选项。
--projectId
string
false
用于标识要使用项目的十六进制字符串。此选项会覆盖配置文件或环境变量中的设置。
--role
strings
true
您想要分配给 API 密钥的角色或角色列表。要分配多个角色,请使用单独的角色标志指定每个角色,或使用一个角色标志以逗号分隔列表指定所有角色。有关 CLI 所接受值的详细信息,请参阅 Atlas API 规范中角色的 Items Enumhttps://mongodb.ac.cn/docs/atlas/reference/api-resources-spec/v2/#tag/Programmatic-API-Keys/operation/createProjectApiKey/.
名称
类型
必需
描述
-P, --profile
string
false

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

API Key '<ID>' created.
Public API Key <PublicKey>
Private API Key <PrivateKey>
# Create an organization API key with the ORG_OWNER role and assign it to the project with ID 5e2211c17a3e5a48f5497de3:
mongocli iam projects apiKeys create --desc "My API key" --projectId 5e1234c17a3e5a48f5497de3 --role ORG_OWNER --output json

返回

assign