Edit

Share via


Quickstart: Create an Azure DocumentDB cluster by using the Azure portal

In this quickstart, you create a new Azure DocumentDB cluster. This cluster contains all of your typical MongoDB resources: databases, collections, and documents. The cluster provides a unique endpoint for various tools and drivers to connect to Azure DocumentDB and perform everyday operations.

Prerequisites

  • An Azure subscription

    • If you don't have an Azure subscription, create a free account

Create a cluster

To get started, you first need to create an Azure DocumentDB cluster, which serves as the foundation for storing and managing your NoSQL data.

  1. Sign in to the Azure portal (https://portal.azure.com).

  2. From the Azure portal menu or the Home page, select Create a resource.

  3. On the New page, search for and select Azure DocumentDB.

    Screenshot showing search for Azure DocumentDB.

  4. On the Create Azure DocumentDB cluster page and within the Basics section, select the Configure option within the Cluster tier section.

    Screenshot showing Configure cluster option.

  5. On the Scale page, configure these options and then select Save to persist your changes to the cluster tier.

    Value
    Cluster tier M30 tier, 2 vCore, 8-GiB RAM
    Storage per shard 128 GiB

    Screenshot of configuration options for compute and storage for a new Azure DocumentDB cluster.

  6. Back in the Basics section, configure the following options:

    Value
    Subscription Select your Azure subscription
    Resource group Create a new resource group or select an existing resource group
    Cluster name Provide a globally unique name
    Location Select a supported Azure region for your subscription
    MongoDB version Select 8.0
    Admin username Create a username to access the cluster as a user administrator
    Password Use a unique password associated with the username

    Screenshot showing cluster parameters.

    Tip

    Record the values you use for username and password. These values are used later in this guide. For more information about valid values, see cluster limitations.

  7. Select Next: Networking.

  8. In the Firewall rules section on the Networking tab, configure these options:

    Value
    Connectivity method Public access
    Allow public access from Azure services and resources within Azure to this cluster Enabled
  9. Add a firewall rule for your current client device to grant access to the cluster by selecting + Add current client IP address.

    Screenshot showing network configurations.

    Tip

    In many corporate environments, developer machine IP addresses are hidden due to a VPN or other corporate network settings. In these cases, you can temporarily allow access to all IP addresses by adding the 0.0.0.0 - 255.255.255.255 IP address range as a firewall rule. Use this firewall rule only temporarily as a part of connection testing and development.

  10. Select Review + create.

  11. Review the settings you provide, and then select Create. It takes a few minutes to create the cluster. Wait for the resource deployment is complete.

  12. Finally, select Go to resource to navigate to the Azure DocumentDB cluster in the portal.

Screenshot showing goto resource options.

Get cluster credentials

Get the credentials you use to connect to the cluster.

  1. On the cluster page, select the Connection strings option in the resource menu.

  2. In the Connection strings section, copy or record the value from the Connection string field.

Screenshot showing connection strings option.

Important

The connection string in the portal doesn't include the password value. You must replace the <password> placeholder with the credentials you entered when you created the cluster or enter the password interactively.

Connect using MongoDB Shell from Quick Start

To connect directly to Azure DocumentDB using MongoDB Shell, use the Quick Start experience available on the resource's page in the Azure portal.

  1. In the cluster resource page, select Quick start (preview) from the navigation menu.

  2. Then, select Open MongoDB shell.

  3. Wait for the MongoDB Shell environment to start.

  4. Once the environment is ready, enter Y to accept the notice.

    Note

    If you're experiencing an issue connecting using MongoDB Shell after accepting the notice, make sure Azure Cloud Shell has access to your cluster.

  5. Now, enter your password to connect your cluster to Cloud Shell.

Perform test queries

Verify that you're successfully connected to your cluster by performing a series of test commands and queries.

  1. Check your connection status by running the connectionStatus command.

    db.runCommand({connectionStatus: 1})
    
    {
      ...
      ok: 1
    }
    
  2. List the databases in your cluster.

    show dbs
    
  3. Switch to a specific database. Replace the <database-name> placeholder with the name of any database in your cluster.

    use <database-name>
    

    Tip

    For example, if the database name is inventory, then the command would be use inventory.

  4. List the collections within the database.

    show collections
    
  5. Find the first five items within a specific collection. Replace the <collection-name> placeholder with the name of any collection in your cluster.

    db.<collection-name>.find().limit(5)
    

    Tip

    For example, if the collection name is equipment, then the command would be db.equipment.find().limit(5).

Clean up resources

When you're done with the Azure DocumentDB cluster, you can delete the Azure resources you created so you don't incur more charges.

  1. In the Azure portal search bar, search for and select Resource groups.

    Screenshot showing option for searching resource groups.

  2. In the list, select the resource group you used for this quickstart.

    Screenshot showing resource group.

  3. On the resource group page, select Delete resource group.

  4. In the deletion confirmation dialog, enter the name of the resource group to confirm that you intend to delete it. Finally, select Delete to permanently delete the resource group.

    Screenshot showing delete resource group confirmation button.