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.2 clusters, use the 3.2.6 or later version of the mongo shell with TLS/SSL support.
  • 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. The SNI TLS extension is supported by version 3.4 of the mongo shell and up.

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.

Go to the Clusters view. Click the Connect button for the cluster to which you wish 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 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

Download and install the Mongo shell.

  1. In the Choose a connection method step, select Connect with the Mongo Shell.

  2. Click your operating system at the top of the dialog.

  3. Click Download to download the shell or click Copy to copy the download URL.

    • For Linux and macOS, run the following command in a terminal to download the Mongo shell from the command line:

      curl -Of <URL>
      
    • For Windows, run the following command in PowerShell to download the installer:

      curl -Uri <URL> -Outfile <path/to/<filename>.zip
      
  4. Extract the Mongo shell.

    • For Linux and macOS, run the following command in a terminal to extract the shell:

      tar -xf ./<filename>.tgz
      
    • For Windows, double-click the .msi file in File Explorer and proceed through the installation wizard.

  5. Add the bin directory to your PATH environment variable.

    • For Linux and macOS, run the following command in a terminal:

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

      Note

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

    • For Windows, use the following procedure:

      1. Click Start 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.
5

Connect to your Atlas cluster with the Mongo shell.

The Connect dialog displays the full command for connecting the Atlas cluster with the mongo shell.

  1. Select the connection string for your mongo shell version:

    • For version 3.6 or later, click I am using shell 3.6 or later.
    • For version 3.4 or earlier, click I am using shell 3.4 or earlier.

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

    mongo --version
    

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

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

    • For version 3.6 or later, the shell will prompt you for the --password parameter.
    • For version 3.4 or earlier, the connection string includes the --password parameter. Edit the placeholder value for the parameter.

    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 parameter with the username of a different MongoDB user.