Manvendra Singh
Create a stored procedure

Managing Cosmos DB using Azure storage explorer

July 29, 2022 by

This article will explain how to perform various activities for Azure cosmos DB using Azure storage explorer. The storage explorer is a very useful desktop utility that helps admins to manage Azure storage without accessing the Azure portal. We can also connect to Azure Cosmos DB accounts using this tool but this feature will be deprecated in the future. As of now, it is supported so I decided to explore it for cosmos DB activities.

Azure Cosmos DB is a fully managed NoSQL database service in the Azure cloud that is globally distributed and suitable for modern-day application development. It is a faster, easily scalable, highly available, and secure database service.

Perform various Cosmos DB activities using Azure storage explorer

I will show you the various cosmos DB activities using storage explorer in this section. Let me start with connecting to an Azure account to see cosmos DB accounts if they are already created on your Azure account.

Connect to Azure Account using Azure storage explorer

Launch Azure storage explorer on your desktop. Click on the View tab to display the list of options. Choose Account Management to select your Azure account.

Connect to Azure account using storage explorer

The below screen will appear once you will click on Account Management on the above screen. I have selected my desired subscription from the below image by clicking at their respective checkbox. Now, click on the Open Explorer tab showing below the checkbox of the Azure account.

Connect to Azure account using storage explorer

You can see the subscription is displayed in the below explorer. Expand Cosmos DB Accounts option showing under-connected subscription. We don’t have any cosmos DB account under this subscription so it is not displaying any details under this option. The support for cosmos DB accounts using Azure storage explorer will be deprecated in future versions that is why you can see deprecated is showing besides cosmos DB accounts option.

Connect to Azure account using storage explorer

I have shown you how to connect to an Azure account to see connected Cosmos DB accounts in Azure storage explorer in this section. Next, let’s create a cosmos DB account on the Azure portal and connect it to storage explorer to perform various activities.

Create an Azure Cosmos DB Account

Log in to the Azure portal. Type Azure Cosmos DB in the search bar to display this service. The below page will display once you click on the cosmos DB option. All cosmos DB accounts will display on this page. As we haven’t provisioned cosmos DB yet so it is not showing any details in the below image. Let’s go ahead and create a cosmos DB account first.

Click at + Create option given just below the Azure Cosmos DB heading or click on the Create Azure Cosmos DB account tab given in the center of the below image.

Azure cosmos DB page

The next screen will come to choose the API as per our workload. I have chosen recommended API Core (SQL) from the below image and hit the Create button given for this option.

Choose desired API for cosmos db account

Below screen named Create Azure Cosmos DB Account -Core (SQL) will appear to fill all required details to create a Cosmos DB account. If you will choose a different API than Core SQL then you will get a similar form for that API to create a Cosmos DB account.

As I have to demonstrate it in storage explorer so I kept all default settings as it is.

Create Azure cosmos DB account

Once you entered all details on all tabs showing in the above image then hit the Review + create button to start the validation process. You can see validation is successful in the below image. Now click on Create button to proceed.

validation

Deployment of Azure cosmos DB account creation will start processing once you will click on create a button of the above image. You will get the below screen once the deployment will be completed. Click at Go to resource tab jump to cosmos DB account.

cosmos db account created

Let’s go ahead and connect to this cosmos DB account using Azure storage explorer in the next section.

Connect to Azure Cosmos DB account using Azure storage explorer

There are 2 ways to connect to an Azure Cosmos DB account using storage explorer. One is using Azure account through which we have connected and expanded Cosmos DB account in the first section, another way is directly connect to cosmos DB account without connecting to Azure account. Let me show you the first option in the below image. Below the screen is the replica of 3rd image showing above where we have connected to the Azure account but there was no cosmos DB account. Now we will click on Refresh All link highlighted in the below image. Once you will refresh it, the newly created cosmos DB account will start appearing under its section of the below image.

Connect to Azure account using storage explorer

The second option is to directly connect to Azure Cosmos DB account without connecting to the whole Azure account. You need PRIMARY CONNECTION STRING of newly created Azure cosmos DB account or any existing cosmos DB account which you want to connect to storage explorer. You need to access the Keys tab given under Settings of cosmos DB account to get the primary connection string through the Azure portal.

The below image is showing keys tab details to display all the connection strings. Click at the copy icon given in the dark red rectangle in the right-hand side pane.

Get the primary connection string of cosmos db account

Now, go back to Azure storage explorer and remove all connected Azure accounts as shown in the below image where we can see no Azure account is connected. Now, click on Open Explorer to get the explorer view.

Remove all Azure accounts from storage explorer

Here, you can see the Cosmos DB Accounts option as shown in the below image. Right-click at this option and click at Connect to Cosmos DB… to get the window where we will be entering the primary connecting string for our newly created cosmos DB account to establish a connection using storage explorer.

Connect to cosmos db account using Azure storage explorer

The below screen will appear to enter the connection string. The primary connect string will be entered in the Connection string input box.

Enter connection strinigs

Enter the copied connection string from the above step in the connection string box, Account label will automatically be recognized and displayed once you enter the copied connection string. You can see it in the below image, I did not enter the Account label, it is already filled post entering the connection string. Now, click on the Next button of the below image.

Enter connection strings of cosmos db account

A Summary screen will appear to validate connection details and if all looks fine then hit the Connect button given bottom side of the below image.

Verify connection string while connecting  to cosmos db account

Now, we can see our newly created cosmos DB account cosmosdb19oct2021 in Azure storage explorer. If it is not visible to you then click on Refresh All link shown in the below image.

Connect to cosmos db account using Azure storage explorer

We have successfully connected to an Azure Cosmos DB account using Azure storage explorer in the above image. Now, I will show you various database-level activities which we can perform to cosmos DB account using storage explorer.

Create a Cosmos database using storage explorer

We have created a cosmos DB account and connected it to storage explorer. Now, let’s explore all options which we can perform on this cosmos DB account using Azure storage explorer. Right-click at the connected database account to get the list of activities we can perform at the cosmos DB account level and the list of such activities can be seen in the below image.

List of options which we can perform at cosmos db account level

Let me show you how to create a database in this cosmos DB account. Click at Create Database option from the above image, you will get the below text box to enter the name of the database.

Create New Database

Enter the name of the database and press enter to create it. You can see database mdscosmosDB has been created under the cosmos DB account cosmosdb19oct2021.

New database

We have created a database in the cosmos DB account in this section. Now, we will perform database-level activities in the next section.

Create Collections in Azure Cosmos database using Azure storage explorer

I assume you already have a cosmos DB account and a database. You have connected to cosmos DB account using storage explorer as shown in the below image. Now, we will explore all activities which can be performed for the database created in a cosmos DB account.

Expand connected cosmos DB account name and right-click at the database name showing in the cosmos DB account tree. You can see the list of activities that we can do to this database using storage explorer.

List of activities which can be performed at database level

Let me show you how to create a collection in this database. Click on Create Collection… option shown in the above image. You will get below the window to enter the collection ID and define the storage capacity for the collection.

Create new collection

Enter the details required to proceed with collection creation. I have entered them as shown in the below image and clicked on the Ok button.

Create new collection

You can see the collection is created in the database in the below image. A list of objects is displayed under the collection tree, like documents, stored procedures, triggers, user-defined functions.

New collection

You can go ahead and test other activities which we can do at the database level. If you want to delete this database then you can choose this option from the list that came after right-clicking on the database name. Make sure you have a backup in place in case you need this data in the future.

Add a new document to a cosmos DB collection using Azure storage explorer

Now, you can go ahead and add a document to the above-created collection. Click at the Documents option showing in the left side pane of the below image under the newly created collection. You will get document details explorer in the right-side pane. Click on the New Document option shown at top of the image.

Click at New document option

Below screen with JSON format template will come to create a document. Here you can enter the ID number and other fields and their details which you want to add to this document and hit the Save button to save this document.

Open New document window

I have created a document with below JSON field details and clicked on the save button to store it. If you click on the Save button, there are a few system-generated fields will be added automatically to the below JSON.

Create the document using JSON

Have a look at the below image, here I have added till Tags field, but the remaining field is added post clicking at the Save button.

Save the newly created document

Similarly, you can create multiple documents by clicking on the New Document option and once you will save them it will look like the below image.

Create a New document

If you want to delete any document then you can select the respective document ID from the ID column and hit the Delete button given in the ribbon bar.

Delete a document

Perform other cosmos DB activities using Azure storage explorer

We can also perform other activities like we can create a new stored procedure by doing a right-click at this option and choosing to Create Stored Procedure…

Create a stored procedure

Once you click on the above option, it will ask you to enter its name and once you press enter below screen will come with a sample stored procedure in the right side pane of the stored procedure name.

Create a stored procedure

Conclusion

Azure storage explorer is a very useful desktop application to manage Azure storage and other Azure cloud-related services like cosmos DB and data lake services. Today I have explored how to connect to Azure Cosmos DB account using Azure storage explorer and perform various activities on cosmos DB account and its objects using storage explorer without going to Azure portal. You have also learned how to create a cosmos DB account in this article.

Manvendra Singh
Azure

About Manvendra Singh

Manvendra is a database enthusiast, currently working as a Senior Architect at one of the top MNC. He loves to talk and write about database technologies. He has lead and delivered many projects from designing to deployments on Migrations to the cloud, heterogeneous migrations, Database consolidations, upgrades, heterogeneous replication, HA / DR solutions, automation, and major performance tuning projects. You can also find him on LinkedIn View all posts by Manvendra Singh

168 Views