Docs Menu
Docs Home
/
MongoDB Compass

Connect to MongoDB

On this page

  • Considerations
  • Connect
  • Connect to Compass from the Command Line

This page outlines how to use MongoDB Compass to connect to a MongoDB host. You can connect to a standalone, replica set, or sharded cluster host.

Note

MongoDB Atlas

If you need to create a MongoDB host, consider using MongoDB Atlas. Atlas is a cloud-hosted database-as-a-service which requires no installation, offers a free tier to get started, and provides a copyable URI to easily connect Compass to your deployment.

If you need to install Compass, see Download and Install Compass for instructions.

  • When connecting Compass to a replica set, it is not recommended to connect directly to an individual replica set member. If the member to which you are connected switches from a primary member to a secondary or vice versa as the result of an election, Compass may either forcibly close the connection or display stale data.

    Instead, to connect to a replica set, use either the replica set SRV record or Replica Set Name when filling in your connection information.

  • Starting in MongoDB Compass 1.19, Compass displays a warning message when connected to non-genuine MongoDB instances as these instances may behave differently from the official MongoDB instances; e.g. missing or incomplete features, different feature behaviors, etc.

  • Starting in version 1.39.2, MongoDB Compass no longer supports migrating from legacy connection files that pre-date version 1.31.0. Legacy connections refer to an internal Compass connection-options format that is stored on disk and no longer supported after version 1.39.0.

    If you have legacy connections saved in your favorites, export the connections on version 1.39.0 to convert them into the new format before updating to version 1.39.2 or later.

If your connection name is already in the Connections Sidebar of your Compass window, click on the connection name to connect.

Otherwise, you can connect your deployments by either:

  • Providing your connection string.

  • Specifying Advanced Connection Options. Advanced connection options allow you to specify authentication, TLS/SSL, and SSH connection options. To learn more, see Advanced Connection Options.

Note

Starting in version 1.44.0, you can connect to multiple MongoDB instances at once through Compass.

When you provide a connection string, Compass supports most Connection String Options supported by MongoDB.

By default, Compass's default socketTimeoutMS value is 60000, or 60 seconds. If you are frequently experiencing timeouts in Compass, consider setting this option to a higher value in your connection string.

For a complete list of the connection string options that Compass supports, see the Compass Connection README on GitHub.

1

In the bottom panel of the Connections Sidebar, click Add New Connection to open the New Connection modal.

If you already have connections listed in the Connections Sidebar, click the icon on the top right of the sidebar to open the New Connection modal.

2

If you have the connection string for your deployment available, you can paste the string directly into the dialog box. You can use either the Standard Connection String Format or the DNS Seedlist Connection Format.

To obtain the connection string for an Atlas cluster:

  1. Navigate to your Atlas Clusters view.

  2. Click Connect for your desired cluster.

  3. Click Connect with MongoDB Compass.

  4. Copy the provided connection string.

Warning

If you click into the MongoDB Compass connection form to edit your connection string, Compass shows credentials in plaintext by default.

To edit your connection string credentials without exposing your password, use the Advanced Connection Options > Authentication tab on the Compass connection form.

To learn how to format the connection string for a deployment that is not hosted on Atlas, see Connection String URI Format.

3

Use the name field to enter a name for your connection. If you do not specify a name, Compass uses the cluster's hostname as the connection name.

4

Use the color drop-down menu to select a label color for your connection. When you connect to a connection, the label color is the background color of tabs that reference your connection.

5

If you want to save the connection as a favorite, check the Favorite this connection option in the modal.

6

Click Save or Save & Connect to navigate to the Compass Home Page.

Important

Required Access

Once you are connected to your MongoDB deployment, you may require specific user roles to access various Compass features. For more information on the required roles for Compass features, see Required Access.

The advanced connection options provide additional ways to connect Compass to MongoDB. Advanced connection options allow you to specify authentication, TLS/SSL, and SSH to securely connect to your deployment.

For details, see Advanced Connection Options.

You can start a Compass session from the command line.

In enterprise environments, a scripted start can make it easier to deploy Compass. For example, to limit access to sensitive systems, you can configure a command line start so that Compass can run on a jump host.

For details, see Start Compass from the Command Line.

Tip

See also:

To learn how to disconnect your deployment, see Disconnect from MongoDB

Back

Edition Capabilities