Navigation

Connect via mongo Shell

The Connect dialog for a cluster provides the details to connect to a cluster via the mongo shell.

For MongoDB 3.6 clusters, use the 3.6.0 or later version of the mongo shell with TLS support.

Prerequisites

TLS

Clients must support TLS to connect to an Atlas cluster.

Clients must support the SNI TLS extension to connect to an Atlas M0 Free Tier or M2/M5 shared starter cluster. MongoDB 3.6 and later shell supports the SNI TLS extension.

Whitelist

To access a cluster, you must connect from an IP address on the Atlas project’s IP whitelist. If you need to add an IP address to the whitelist, you can do so in the Connect dialog. You can also add the IP address from the Security tab.

MongoDB User

To access a cluster, you must create a MongoDB User with access to the desired database(s) on your Atlas cluster. MongoDB users are separate from Atlas users. MongoDB users have access to MongoDB databases, while Atlas users have access to the Atlas application itself.

You can create a MongoDB user to access to your Atlas cluster in the Connect dialog. You can also add the MongoDB user from the Clusters view.

Connect to Your Cluster

1

Open the Connect dialog.

In the Clusters view, click the Connect button for the cluster to which you want to connect.

2

Choose your Connection Security.

Choose Connection Type from the set of available buttons.

Use this connection type for whitelisted public IP addresses.

Use this connection type if you enabled peering:

  • For GCP or Azure and are connecting with the mongo shell from a peered network, or
  • For AWS and are connecting with the mongo shell from a peered network which uses a custom DNS service.

If neither of these apply, whitelist your IP address and use the Standard Connection string. If you are connecting directly to Atlas from an office or home network, this might be the preferred option.

Use the connection string for the appropriate interface endpoint if you are connecting with the mongo shell over a Private Endpoint connection either because the mongo shell:

  • Runs inside your cloud provider network, or
  • Has transitive network access to your cloud provider network.

If neither of these apply, whitelist your IP address and use the Standard Connection string. If you are connecting directly to Atlas from an office or home network, this might be the preferred option.

3

Choose how you want to limit connections to your cluster.

Whitelist a Connection IP Address

Important

Skip this step if Atlas indicates in the Setup Connection Security step that you have already configured a whitelist entry in your cluster. To manage the IP whitelist, see Add Entries to the Whitelist.

Atlas allows standard client connections to the cluster from entries in the project’s whitelist. The project whitelist differs from the API whitelist, which restricts API access to specific IP or CIDR addresses.

If the whitelist is empty, Atlas prompts you to add an IP address to the project’s whitelist. You can either:

  • Click Add Your Current IP Address to whitelist your current IP address.
  • Click Add an IP Address to add a single IP address or a CIDR-notated range of addresses.

Provide an optional description for the newly added IP address or CIDR range. Click Add IP Address to add the address to the whitelist.

Whitelist a Connection IP Address

Important

Skip this step if Atlas indicates in the Setup Connection Security step that you have already configured a whitelist entry in your cluster. To manage the IP whitelist, see Add Entries to the Whitelist.

Atlas allows standard client connections to the cluster from entries in the project’s whitelist. The project whitelist differs from the API whitelist, which restricts API access to specific IP or CIDR addresses.

If the whitelist is empty, Atlas prompts you to add an IP address to the project’s whitelist. Click Add a Different IP Address to add a single IP address or a CIDR-notated range of addresses.

Provide an optional description for the newly added IP address or CIDR range. Click Add IP Address to add the address to the whitelist.

Choose PrivateLink

Select the PrivateLink in your AWS region from the Choose PrivateLink menu.

4

Create a MongoDB User.

Important

Skip this step if Atlas indicates in the Setup connection security step that you have at least one MongoDB user configured in your project. To manage existing MongoDB users, see Add MongoDB Users.

To access the cluster, you need a MongoDB user with access to the desired database(s) on the cluster in your project. If your project has no MongoDB users, Atlas prompts you to create a new user with the Atlas Admin role.

  1. Enter the new user’s Username
  2. Enter a Password for this new user or click Autogenerate Secure Password.
  3. Click Create MongoDB User to save the user.

Use this user to connect to your cluster in the following step.

Once you have whitelisted an IP address and added a MongoDB user, click Choose Your Connection Method.

5

Connect to your Atlas cluster with the mongo shell.

Select Connect with the Mongo Shell.

The next screen offers you options to proceed based on whether or not you already have the mongo shell installed on your system.

Select your OS from the dropdown menu.

  1. Download using one of the following options:
    • Click Download Mongo Shell to begin the download, or
    • Click Fetch via URL to copy a download URL to your clipboard.
      • Use curl to fetch the installer file, or
      • Paste the URL in a browser window.
  2. Double-click the .msi file in Windows Explorer and proceed through the installation wizard.
  3. Add the bin directory to your command path.
    1. Click windows icon and select Control Panel.
    2. Click System and Security, then System, then Advanced System Settings.
    3. Click Environment Variables.
    4. Select Path and click Edit.
    5. Add the bin directory where the installer placed your MongoDB executables and click OK.
  1. Use the Homebrew command provided.
  2. Copy the Homebrew command from the Atlas UI window and run it in a terminal.
  3. Step 3 of the Atlas UI modal displays a copyable connection string. This string includes the name of the MongoDB user that can authenticate with the cluster. Copy this string. To connect as a different MongoDB user, change the –username option.
  4. Paste the mongo command and connection string into a terminal. Run the command. The shell prompts you for the password.
  1. Download using one of the following options:

    • Click Download Mongo Shell to begin the download, or
    • Click Fetch via URL to copy a download URL to your clipboard.
      • Use curl to fetch the installer file, or
      • Paste the URL in a browser window.
  2. Run the following command in a terminal to extract the mongo shell:

    tar -xzf ./<filename>.tgz
    
  3. Add the bin directory to your PATH environment variable.

    export PATH=/<extraction-directory>/bin:$PATH
    

    Note

    If you run this command, it persists for the current shell session. To update the variable across shell sessions and reboots, edit the PATH environment variable in ~/.profile.

  4. Step 3 of the Atlas UI modal displays a copyable connection string. This string includes the name of the MongoDB user that can authenticate with the cluster. Copy this string. To connect as a different MongoDB user, change the –username option.

  5. Paste the mongo command and connection string into a terminal. Run the command. The shell prompts you for the password.

  1. Select your shell version from the dropdown menu. To check which version of the mongo shell is installed on your system, run the following command from a terminal:

    mongo --version
    

    If your shell version is older than 3.4, MongoDB recommends that you upgrade to the newest version.

  2. Step 2 of the Atlas UI modal displays a copyable connection string. This string includes the name of the MongoDB user that can authenticate with the cluster. Copy this string. To connect as a different MongoDB user, change the –username option.

  3. Paste the mongo command and connection string into a terminal. Run the command. The shell prompts you for the password.

    • For shell version 3.6 or later, the shell prompts you for the password.
    • For shell version 3.4 or earlier, the connection string includes the –password option. Edit the placeholder value for the option.

Troubleshooting

If you are experiencing issues connecting to your cluster, see Troubleshoot Connection Issues.