Docs Menu
Docs Home
/ /
MongoDB CLI
/ / / /

mongocli iam projects apiKeys assign

On this page

  • Syntax
  • Arguments
  • Options
  • Inherited Options
  • Examples

Assign the specified organization API key to your project and modify the API key's roles for the project.

When you modify the roles for an organization API key with this command, the values you specify overwrite the existing roles assigned to the API key.

To view possible values for the ID argument, run mongocli iam organizations apiKeys list.

Command Syntax
mongocli iam projects apiKeys assign <ID> [options]
Name
Type
Required
Description
ID
string
true
Unique 24-digit string that identifies your API key.
Name
Type
Required
Description
-h, --help
false
help for assign
-o, --output
string
false
Output format. Valid values are json, json-path, go-template, or go-template-file. To see the full output, use the -o json option.
--projectId
string
false
Hexadecimal string that identifies the project to use. This option overrides the settings in the configuration file or environment variable.
--role
strings
true
Role or roles that you want to assign to the API key. To assign more than one role, specify each role with a separate role flag or specify all of the roles as a comma-separated list using one role flag. To learn which values the CLI accepts, see the Items Enum for roles in the Atlas API spec: https://www.mongodb.com/pt-br/docs/atlas/reference/api-resources-spec/v2/#tag/Programmatic-API-Keys/operation/createProjectApiKey/.
Name
Type
Required
Description
-P, --profile
string
false
# Assign an organization API key with the ID 5f46ae53d58b421fe3edc115 and grant the GROUP_DATA_ACCESS_READ_WRITE role for the project with ID 5e2211c17a3e5a48f5497de3:
mongocli iam projects apiKeys assign 5f46ae53d58b421fe3edc115 --projectId 5e1234c17a3e5a48f5497de3 --role GROUP_DATA_ACCESS_READ_WRITE --output json

Back

apiKeys