For AI agents: a documentation index is available at https://www.mongodb.com/zh-cn/docs/llms.txt — markdown versions of all pages are available by appending .md to any URL path.
Docs Menu

Connect from the Atlas CLI

When you connect to an existing Atlas account from the Atlas CLI, you can authenticate with one of the following options for the atlas auth login command:

Option
Authentication Method
Use Case

UserAccount

Atlas login credentials and an authentication token

Best for non-programmatic use

ServiceAccount

Service Account

Best for programmatic use with a Service Account

APIKeys

API keys

Best for programmatic use with an API Key

Important

For Atlas CLI versions before 1.47, 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. Atlas CLI 1.47+ attempts to store credentials securely.

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:

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.

There was an error fetching your organizations: Global user is
from outside access listed subnets.
To fix the conflict, open the :ref:`configuration file
<config-toml-location>`, remove the default profile, and
run ``atlas auth login`` again.
.. step:: Issue commands using the ``--projectId`` and ``--orgId`` flags.
When you run :ref:`Atlas CLI commands <atlas>` for
the duration of your Atlas CLI session, specify your Project ID and Org ID
using the ``--projectId`` and ``--orgId`` flags.
.. example::
.. code-block:: sh
atlas alerts list --projectId 60b3c81153cf986293e2608b
.. tab:: Service Account
:tabid: service-account
.. procedure::
:style: normal
.. include:: /includes/steps-atlas-cli-auth-prog-default.rst
.. step:: Select the ``ServiceAccount`` option and press ``Enter``.
.. step:: Enter the Service Account Credentials.
Provide the client ID and secret of the Service Account you created and press ``Enter``.
.. step:: Select the default project and output format.
a. If your Service Account is at organization level, the
CLI prompts you to select a default project to run
commands on.
#. Select the output format.
.. step:: Issue commands using the ``--projectId`` and ``--orgId`` flags.
When you run :ref:`Atlas CLI commands <atlas>` for
the duration of your Atlas CLI session, specify your Project ID and Org ID
using the ``--projectId`` and ``--orgId`` flags.
.. example::
.. code-block:: sh
atlas alerts list --projectId 60b3c81153cf986293e2608b
.. tab:: API Keys
:tabid: api-keys
.. procedure::
:style: normal
.. include:: /includes/steps-atlas-cli-auth-prog-default.rst
.. step:: Select the ``APIKeys`` option and press ``Enter``.
.. step:: Enter your |api| keys.
Enter your public and private keys when prompted.
.. step:: Accept the default profile options.
Accept the remaining default profile options by pressing :guilabel:`Enter`
when the following options display:
- ``Default Org ID``
- ``Default Project ID``
- ``Default Output Format``
- ``Default MongoDB Shell Path``
.. step:: Issue commands using the ``--projectId`` and ``--orgId`` flags.
When you run :ref:`Atlas CLI commands <atlas>` for
the duration of your Atlas CLI session, specify your Project ID and Org ID
using the ``--projectId`` and ``--orgId`` flags.
.. example::
.. code-block:: sh
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.