Quickstart: Use Azure Data Studio to connect and query Azure Cosmos DB API for MongoDB (Preview)

This quickstart shows how to use Azure Data Studio to connect to the Azure Cosmos DB API for MongoDB.


To complete this quickstart, you need Azure Data Studio and an Azure Cosmos DB API account.

Connect to an Azure Cosmos DB API for MongoDB account

  1. Start Azure Data Studio.

  2. The first time you start Azure Data Studio the Connection dialog opens. If the Connection dialog doesn't open, select the New Connection icon in the SERVERS page:

    Screenshot of new connection icon in the Servers sidebar.

  3. In the dialog that appears, select Browse, and then select the + icon to sign in to Azure.

    Screenshot of the plus button to add new Azure account in the Connection dialog.

  4. Once you're signed in to Azure, select the Azure Cosmos DB account you'd like to access or fill in the Connection Details from fields using the details in this table.

    Setting Value Description
    Connection type Mongo account Set this value to Mongo account to use with Azure Cosmos DB API for MongoDB.
    Mongo account [cosmos-account-name] Name of Azure Cosmos DB account.
    Authentication type Azure Active Directory - Universal with MFA support Choose between Azure Active Directory or Basic authentication options.
    Account [current-aad-user-name] Only visible if using Azure Active Directory authentication. Select the Azure AD account that you wish to use for authentication.
    Username Only visible if using Basic authentication. Enter the username for authentication.
    Connection String Only visible if using Basic authentication. Enter the connection string for authentication.
    Server group <Default>
    Name (optional) Enter any unique name to use in the SERVERS sidebar.

    Screenshot of dialog with credentials required to create a connection.

  5. Select Connect.


    If you selected Azure Active Directory authentication, you may be prompted to select a MongoDB connection string value to use for your connection.

Your server will open in the SERVERS sidebar after you've successfully connected.

Create a database and collection

The following steps will create a database named SourceDatabase and a collection named People:

  1. Open the context menu for your account, and select Create Database.

    Screenshot of the create database option in the Mongo DB context menu.

  2. In the Database and Collection popup dialogs, use the details in this table.

    Prompt Value
    Database name SourceDatabase
    Collection name People
  3. After the operation completes, the new database should appear in the list of databases.


    If the database does not appear in the list, select Refresh.

  4. Expand the SourceDatabase and People nodes in the SERVERS sidebar.

    Screenshot of database and collection hierarchy under the Mongo account note in the SERVERS sidebar.

Create a sample collection

The following steps will populate the People collection with a sample data set:

  1. Select Databases to navigate to the list of databases in your account.

    Screenshot of option to navigate to databases view.

  2. Select the SourceDatabase item in the list of databases.

    Screenshot of database list item named Source Database within databases list.

  3. In the header menu, select Import Sample Data. In the confirmation dialog, select Yes.

    Screenshot of dialog option to perform an import.

  4. Wait for the import operation to complete.


    The import operation may take a few minutes to finish.

Query the data

The following steps will use the Mongo Shell to execute a query and view the results of the query:

  1. In the menu for your database, select Open Mongo Shell.

    Screenshot of menu option to open Mongo Shell.

  2. Execute the following query in the shell.



    The pretty() method in Mongo displays the results of a query in a format that's easy to read. To learn more, see the official MongoDB documentation for cursor.pretty.

  3. Observe the output of the query within the shell. The output should contain

    Screenshot of Mongo Shell query results.

Next steps

In this quickstart, you've learned how to create an API for MongoDB account, create a database and a collection in Azure Data Studio, and query sample data. You can now use Azure Data Studio to review real data in your database.