Docs Menu
Docs Home
/ /
MongoDB Command Line Interface
/ / /

mongocli iam project apikey list

On this page

  • Syntax
  • Options
  • Output
  • Examples

The iam project apikey list command lists the API keys for the specified project.

You must have GROUP_USER_ADMIN privileges to list API keys for the project.

mongocli iam project|projects apiKey|apiKeys|apikeys list|ls
[ --projectId <project-id> ]
[ --output|-o <output-format> ]
[ --profile|-P <profile-name> ]

Note

Use -h or --help to view the command-line help for this command.

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:

  • json for output in JSON format

  • go-template for custom output using the Go template

  • go-template-file for custom output specified using Go template file

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

If the command succeeds, it returns the following output in the default format. If the command returns errors, see Troubleshooting for recommended solutions.

ID PUBLIC KEY DESCRIPTION
<key-id-1> <public-key-1> <key-description-1>
<key-id-2> <public-key-2> <key-description-2>

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:

The following command retrieves the API keys for a project using the default profile, which contains credentials and the project ID. The output is returned in the default format.

mongocli iam project apikey list

The previous command prints the following to the terminal.

ID PUBLIC KEY DESCRIPTION
5f4578684b4afb5e8cd44ee9 mkoztppy Project Owner
5f469ea0f2c5937c5cdb1081 hdlvegpx External Read-Only

The following command retrieves the API keys for a project using the myOM profile, which contains credentials and specifies the Ops Manager service. The output is returned in JSON format.

mongocli iam project apikey list --projectId 5e399b9a7a3e5a1772948493 --profile myOM --output json

The previous command retrieves the API keys for a project and prints the following to the terminal in JSON format.

[
{
"id": "5f4578684b4afb5e8cd44ee9",
"desc": "Project Owner",
"roles": [
{
"groupId": "5e399b9a7a3e5a1772948493",
"roleName": "GROUP_OWNER"
},
{
"orgId": "5dd6fa0c7a3e5a1d0fa27e35",
"roleName": "ORG_MEMBER"
}
],
"privateKey": "********-****-****-1676fa25614f",
"publicKey": "mkoztppy"
},
{
"id": "5f469ea0f2c5937c5cdb1081",
"desc": "External Read-Only",
"roles": [
{
"orgId": "5dd6fa0c7a3e5a1d0fa27e35",
"roleName": "ORG_MEMBER"
},
{
"groupId": "5e399b9a7a3e5a1772948493",
"roleName": "GROUP_READ_ONLY"
}
],
"privateKey": "********-****-****-a6568963a711",
"publicKey": "hdlvegpx"
}
]

Back

Create a Project API Key