Use MongoDB Compass to connect to Azure Cosmos DB's API for MongoDB


This tutorial demonstrates how to use MongoDB Compass when storing and/or managing data in Azure Cosmos DB. We use the Azure Cosmos DB's API for MongoDB for this walk-through. For those of you unfamiliar, Compass is a GUI for MongoDB. It is commonly used to visualize your data, run ad-hoc queries, along with managing your data.

Azure Cosmos DB is Microsoft's globally distributed multi-model database service. You can quickly create and query document, key/value, and graph databases, all of which benefit from the global distribution and horizontal scale capabilities at the core of Azure Cosmos DB.


To connect to your Azure Cosmos DB account using MongoDB Compass, you must:

Connect to Azure Cosmos DB's API for MongoDB

To connect your Azure Cosmos DB account to Compass, you can follow the below steps:

  1. Retrieve the connection information for your Azure Cosmos DB account configured with Azure Cosmos DB's API MongoDB using the instructions here.

    Screenshot of the connection string blade

  2. Click on the button that says Copy to clipboard next to your Primary/Secondary connection string in Azure Cosmos DB. Clicking this button will copy your entire connection string to your clipboard.

    Screenshot of the copy to clipboard button

  3. Open Compass on your desktop/machine and click on Connect and then Connect to....

  4. Compass will automatically detect a connection string in the clipboard, and will prompt to ask whether you wish to use that to connect. Click on Yes as shown in the screenshot below.

    Screenshot shows a dialog box explaining that you have a connection string on your clipboard.


    If Compass does not automatically detect your connection string, you can still manually paste it into the application.

  5. Upon clicking Yes in the above step, your details from the connection string will be automatically populated. Remove the value automatically populated in the Replica Set Name field to ensure that is left blank.

    Screenshot shows the Replica Set Name text box.

  6. Click on Connect at the bottom of the page. Your Azure Cosmos DB account and databases should now be visible within MongoDB Compass.

Next steps