Docs Menu
Docs Home
/ /
Atlas CLI

Connect from the Atlas CLI

On this page

  • Select a Connection Method
  • Connect With Minimum Required Settings
  • Complete the Prerequisites
  • Follow These Steps
  • Take the Next Steps

When you connect to an existing Atlas account from the Atlas CLI, you can authenticate with one of the following commands:

Command
Authentication Method
Use Case
atlas auth login
Atlas login credentials and an authentication token
Best for non-programmatic use
atlas config init
API keys
Best for programmatic use

Important

API keys are stored in plaintext in the Atlas CLI configuration file. Your API keys are like passwords. Ensure that you secure the configuration file appropriately.

To create a new Atlas account or onboard an existing account that doesn't have any clusters, see Get Started with Atlas.

Select a use case below to learn more about the available connection options:

Use the atlas auth login command to authenticate with your Atlas login credentials and a one-time authentication token. atlas auth login requires manual login and verification of an authentication token, which is valid for 12 hours. API keys are optional when connecting with atlas auth login.

After you run atlas auth login, you can:

  • Connect with minimum required settings and specify the --projectId and --orgId flags with each command. This is the quickest way to get started for first-time login.

  • Save your connection settings in a profile. Profiles store the project IDs, organization IDs, and, optionally, API keys to use in future Atlas CLI sessions. To save time, you can specify a profile instead of using the --projectId and --orgId flags with each command.

You must configure API keys to authenticate with this command.

When you run the atlas config init command, the Atlas CLI prompts you to provide your API keys and automatically creates a profile that stores the API keys. atlas config init is best for programmatic use because it doesn't require manual login or token verification.

When you use connect with atlas config init, you can:

  • Connect with minimum required settings and specify the --projectId and --orgId flags with each command. This is the quickest way to get started for first-time login.

  • Save additional connection settings in a profile. Profiles store the project IDs, organization IDs, and, optionally, API keys to use in future Atlas CLI sessions. To save time, you can specify a profile instead of using the --projectId and --orgId flags with each command.

Select a use case and follow the steps to connect from the Atlas CLI with minimum required settings.

Select a use case and follow the procedure to quickly connect from the Atlas CLI.

1

Run the atlas auth login command in your terminal.

atlas auth login

The command opens a browser window and returns a one-time activation code. This code expires after 10 minutes.

2

If you aren't signed in already, sign into your Atlas account in the browser.

3

Paste your activation code into the browser and click Confirm Authorization.

4

Return to the terminal. If you connect successfully, you see a message:

Successfully logged in as {Your Email Address}.

Accept the default profile configuration by pressing Enter if the following options display:

  • Default Org ID

  • Default Project ID

  • Default Output Format

  • Default MongoDB Shell Path

Important

If you previously set up any profiles with API keys for MongoCLI, your profiles migrate automatically. Some migrated profiles might cause Atlas CLI commands to fail when authenticating with atlas auth login. The following message displays when you run atlas auth login if there is a conflict:

There was an error fetching your organizations: Global user is
from outside whitelisted subnets.

To fix the conflict, open the configuration file, remove the default profile, and run atlas auth login again.

5

When you run Atlas CLI commands for the duration of your Atlas CLI session, specify your Project ID and Org ID using the --projectId and --orgId flags.

Example

atlas alerts list --projectId 60b3c81153cf986293e2608b
1

Run the atlas config init command in your terminal.

atlas config init
2

Enter your public and private keys when prompted.

3

Accept the remaining default profile options by pressing Enter when the following options display:

  • Default Org ID

  • Default Project ID

  • Default Output Format

  • Default MongoDB Shell Path

4

When you run Atlas CLI commands for the duration of your Atlas CLI session, specify your Project ID and Org ID using the --projectId and --orgId flags.

Example

atlas alerts list --projectId 60b3c81153cf986293e2608b

Start using the Atlas CLI commands.

To save connection settings by modifying the default profile or create a different profile, see Save Connection Settings.

Back

Verify Packages