How to connect to Azure Cosmos DB using Azure Cosmos DB Explorer?
Hello Everyone
Welcome to CloudAffaire and this is Debjeet.
In today’s blog post, we will discuss how to connect to Azure Cosmos DB using Azure Cosmos DB Explorer. We will first create an Azure Cosmos DB account using Azure Portal and then will connect to the Azure Cosmos DB account in Azure Cosmos DB explorer. Once connected, we will also create a new database, container and perform CURD operation in our Azure Cosmos DB using Azure Cosmos DB Explorer.
How to connect to Azure Cosmos DB using Azure Cosmos DB Explorer?
Step 1: Create a resource group for Azure Cosmos DB.
Log in to Azure Portal.
Navigate to “Resource Groups”.
Click on “Create” to create a new resource group.
Select your subscription and region and provide a name for the new resource group. Finally, click “Create” to create the new resource group.
Step 2: Create an Azure Cosmos DB account.
Navigate to Azure Cosmos DB service.
Click “Create Azure Cosmos DB Account”.
Select the API type for your Azure Cosmos DB. For this demo, we will use SQL core API.
Provide a name (must be unique globally) and other details and click “Next: Global Distribution”.
Select the distribution level for your Azure Cosmos DB and click “Next: Networking”. To reduce cost, we will not enable global distribution for our Azure Cosmos DB.
Next, select the networking mode for your Azure Cosmos DB and click “Next: Backup Policy”.
Select the backup options for your Azure Cosmos DB and click “Next” Encryption”.
Select the encryption option for your Azure Cosmos DB and click “Next: Tags”.
Optionally, you can tag your Azure Cosmos DB account, Click “Review + Create” to review and create your Azure Cosmos DB account.
Step 3: Connect to Azure Cosmos DB Account With Azure Cosmos DB Data Explorer.
Navigate to Azure Cosmos DB Account > Keys and copy the “Primary Connection String”.
Now open https://cosmos.azure.com/ in another tab of your browser.
Click on “Connect to your account with connection string.
Provide the connection string copied earlier and click “Connect”.
We have successfully connected to our Azure Cosmos DB account in Azure Cosmos DB Explorer.
Now we can use this Azure Cosmos DB Explorer to create new databases, containers and perform CURD operation on our Azure Cosmos database.
Step 4: Create a new database in Azure Cosmos DB using Azure Cosmos DB Explorer.
In Azure Cosmos DB Explorer, click “New Database”.
Provide Database Name (ID) and throughput and click “Create”.
Next, we are going to create an Azure Cosmos DB container inside this database.
Step 5: Create an Azure Cosmos DB container using Azure Cosmos DB Explorer.
In the Azure Cosmos DB Explorer, click “New Container”.
Select the database created in the previous step, provide a name (ID) and partition key for the container and click “OK”.
We have successfully created the Azure Cosmos DB container and database using Azure Cosmos DB Explorer.
Step 6: Insert data into Azure Cosmos DB using Azure Cosmos DB Explorer.
Inside your container click on “items” and then click on “New item”.
Add the below data in the query window and click “Save”.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
{ "id": "1", "productId": "33218896", "category": "Women's Clothing", "manufacturer": "Contoso Sport", "description": "Quick dry crew neck t-shirt", "price": "14.99", "shipping": { "weight": 1, "dimensions": { "width": 6, "height": 8, "depth": 1 } } } |
Similarly, add a second item with the below data.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
{ "id": "2", "productId": "33218897", "category": "Women's Outerwear", "manufacturer": "Contoso", "description": "Black wool pea-coat", "price": "49.99", "shipping": { "weight": 2, "dimensions": { "width": 8, "height": 11, "depth": 3 } } } |
We have successfully inserted data into our Azure Cosmos DB. Next, we are going to update data in Azure Cosmos DB.
Step 7: Update data in Azure Cosmos DB using Azure Cosmos DB Explorer.
Select the item that you want to update and update the value in the query editor. Once updated, click “Update” to update the item in Azure Cosmos DB using Azure Cosmos DB Explorer.
Note: We have updated the “manufacturer” value from “Conteso” to “Cloudaffaire” in this demo.
Step 8: Delete data in Azure Cosmos DB using Azure Cosmos DB Explorer.
To delete an item in Azure Cosmos DB, select the item you want to delete and click on “Delete”.
Confirm the deletion of the item by clicking on the “Delete” button.
Step 9: Clean up.
In the Azure Portal, get inside the resource group that you have created at the very first step of this demo. Click on “Delete resource group” to delete all the resources in your resource group.
Hope you have enjoyed this article. To get more details in Azure Cosmos DB, please refer to the below documentation.
https://docs.microsoft.com/en-us/azure/cosmos-db/