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.4 clusters, use the 3.4.0 or later version of the mongo shell with TLS/SSL support.
  • For MongoDB 3.6 clusters, use the 3.6.0 or later version of the mongo shell with TLS/SSL support.

Prerequisites

TLS/SSL

Clients must have support for TLS/SSL to connect to an Atlas cluster.

Clients must have support for the SNI TLS extension to connect to an Atlas M0 Free Tier or M2/M5 shared starter cluster. MongoDB 3.4 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

Whitelist your connection IP address.

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

Note

You can 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.

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 a Different IP Address to add a single IP address or a CIDR-notated range of addresses.

    For Atlas clusters deployed on Amazon Web Services (AWS) and using VPC Peering, you can add a Security Group associated with the peer VPC.

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

3

Create a MongoDB User.

To access the cluster, you must create a MongoDB user with access to the desired database(s) on the cluster.

Note

You can 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.

If the project has no MongoDB users, Atlas prompts you to create a new user with the Atlas Admin privilege. Enter the new user’s Username and Password and 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.

4

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.

  1. Select your OS from the dropdown menu.

  2. macOS: Use the Homebrew command provided.

    Linux / Windows: Click Download Mongo Shell to begin the download, or click Fetch via URL to copy a download URL to your clipboard. You can either:

    • Use curl to fetch the installer file, or
    • Paste the URL in a browser window.

    Once you have the file, extract the Mongo shell. Select the appropriate tab for your operating system:

  1. Double-click the .msi file in Windows Explorer and proceed through the installation wizard.
  2. 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. Copy the Homebrew command from the Atlas UI window and run it in a terminal.
  2. A copyable connection command appears in Step 3 of the Atlas UI window. Be sure to update the –username option with your MongoDB username.
  3. Copy and paste the mongo command and connection string into a terminal and run it. The shell prompts you for the –password option.
  1. Run the following command in a terminal to extract the mongo shell:

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

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

    Note

    This command applies only to the current shell session. Edit the PATH environment variable in ~/.profile to update the variable across shell sessions and reboots.

  3. A copyable connection command appears in Step 3 of the Atlas UI window. Be sure to update the –username option with your MongoDB username.

  4. Copy and paste the mongo command and connection string into a terminal and run it. The shell prompts you for the –password option.

The connection string includes the user name of a MongoDB user set up for the project for authentication purposes. To connect as a different MongoDB user, update the --username option with the username of a different MongoDB user.

  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. A copyable connection command appears in Step 2 of the Atlas UI window. Be sure to update the –username option with your MongoDB username.

  3. Copy and paste the mongo command and connection string into a terminal and run it.

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

    The connection string includes the user name of a MongoDB user set up for the project for authentication purposes. To connect with a different MongoDB user, update the –username option with the username of a different MongoDB user.

Troubleshooting

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