Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
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.
Sign in to the Azure portal (https://portal.azure.com).
From the Azure portal menu or the Home page, select Create a resource.
On the New page, search for and select Azure DocumentDB.
On the Create Azure DocumentDB cluster page and within the Basics section, select the Configure option within the Cluster tier section.
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 RAMStorage per shard 128 GiB
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.0Admin username Create a username to access the cluster as a user administrator Password Use a unique password associated with the username
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.
Select Next: Networking.
In the Firewall rules section on the Networking tab, configure these options:
Value Connectivity method Public accessAllow public access from Azure services and resources within Azure to this cluster Enabled Add a firewall rule for your current client device to grant access to the cluster by selecting + Add current client IP address.
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.255IP address range as a firewall rule. Use this firewall rule only temporarily as a part of connection testing and development.Select Review + create.
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.
Finally, select Go to resource to navigate to the Azure DocumentDB cluster in the portal.
Get cluster credentials
Get the credentials you use to connect to the cluster.
On the cluster page, select the Connection strings option in the resource menu.
In the Connection strings section, copy or record the value from the Connection string field.
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.
In the cluster resource page, select Quick start (preview) from the navigation menu.
Then, select Open MongoDB shell.
Wait for the MongoDB Shell environment to start.
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.
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.
Check your connection status by running the
connectionStatuscommand.db.runCommand({connectionStatus: 1}){ ... ok: 1 }List the databases in your cluster.
show dbsSwitch 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 beuse inventory.List the collections within the database.
show collectionsFind 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 bedb.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.
In the Azure portal search bar, search for and select Resource groups.
In the list, select the resource group you used for this quickstart.
On the resource group page, select Delete resource group.
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.