mongocli iam project apikey assign
The iam project apikey assign
command assigns an organization API
key to a project and updates the API key roles.
You must have GROUP_USER_ADMIN
privileges to assign an
API key to a project.
Syntax
mongocli iam project|projects apiKey|apiKeys|apikeys assign|update <api-key-id> [ --projectId <project-id> ] [ --output|-o <output-format> ] [ --profile|-P <profile-name> ] [ --role <list-of-roles> ]
Note
Use -h
or --help
to view the command-line help for
this command.
Arguments
Argument | Type | Description | Required? |
---|---|---|---|
<api-key-id> | string | Unique identifier for this API key. | yes |
Options
Option | Type | Description | Required? |
---|---|---|---|
--projectId | string | Unique identifier of the project. If omitted, uses the project ID in the profile or environment variable. | no |
--output , -o | string | Command output format. Valid values are:
If omitted, the command returns output in the default format. | no |
--profile , -P | string | Name of the profile where your credentials are saved. If omitted, uses the default profile. To learn more about creating a profile, see Configure the MongoDB CLI. | no |
--role | string | Role or roles to assign to the API key. To assign more than
one role, you can specify each role with a --role flag or
specify the roles in a comma-separated list with one --role
flag. | no |
Output
If the command succeeds, it returns the following output in the default format. If the command returns errors, see Troubleshooting for recommended solutions.
API Key successfully assigned.
The default output is a subset of the fields returned by this command. For the complete list of JSON fields returned by the command, see the Public API reference for your MongoDB service:
Examples
The following command assigns an organization API key to a project and updates its role using the default profile, which contains credentials and the project ID of the project to assign the API key to. The output is returned in the default format.
mongocli iam project apikey assign 5f46ae53d58b421fe3edc115 --role GROUP_OWNER
The previous command prints the following to the terminal.
API Key successfully assigned.
The following command assigns an organization API key to a
project and updates its role using the myOM
profile, which
contains credentials and specifies the the Ops Manager service. The
output is returned in JSON format.
mongocli iam project apikey assign 5f46ae53d58b421fe3edc115 --role GROUP_DATA_ACCESS_READ_WRITE --output json
The previous command updates the API key does not return a JSON response.