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.

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.

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

From the Connect dialog, review the IP Whitelist.

Atlas only allows client connections to the cluster from entries in the project’s whitelist.

Atlas displays any entries already on the project whitelist in the Connect modal under Check the IP Whitelist. If you do not see the IP address of your client on the list, you can:

  • Click Add Entry 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.

  • Click Add Current IP Address to add your current IP address.

  • Click Allow Access From Anywhere to allow access from any IP address.

    Warning

    Using Allow Access From Anywhere results in all clusters in the Atlas project being publically accessible. Consider the security risks of having public-facing MongoDB clusters before using this option.

3

Download and install the Mongo shell.

  1. Click Connect with the Mongo Shell beneath Choose a connection method.

  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>.msi
      
  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.
4

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.