Simplifying CRUD Operations using Azure Cosmos DB

Introduction

In this article, I will explain the comprehensive guide implementation of the CRUD operations using Azure Cosmos DB. We will divide this article into 2 sections. The first section describes about the creation of Azure Cosmos DB account and the second section describes CRUD operations. Let's get started.

Architecture of Azure Cosmos DB with CRUD

 CRUD Operations using Azure Cosmos DB

This architecture depicts the usage of Azure Cosmos DB with CRUD operations, where one can notice that Azure Cosmos DB contains a massive amount of databases.

The database is a combination of several containers which are ready to be deployed. Containers are a combination of several items that can be stored. Azure Cosmos DB will be able to perform Create, Read, Update, and Delete operations.

Steps to perform CRUD operations using Azure Cosmos DB

The first section describes the creation of the Azure Cosmos DB account as follows.

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

 CRUD Operations using Azure Cosmos DB

Search for Azure Cosmos DB service in the global search bar and then click.

 CRUD Operations using Azure Cosmos DB

Click the Azure Cosmos DB account button.

 CRUD Operations using Azure Cosmos DB

Select Azure Cosmos DB for the NoSQL option and then click Create button.

 CRUD Operations using Azure Cosmos DB

In the Basics tab, first, you have to choose the Subscription.

Click the new Resource group option.

Type the account name as retailaccount01 in the instance details option.

Specify the region as US West US option.

Select the capacity mode as Provisioned Throughput option.

Check the option to limit the total amount of throughput provisioned on this account option.

 CRUD Operations using Azure Cosmos DB

Click Review+ Create button on the basics tab.

You will get the Validation Success message which is appeared on the screen.

 CRUD Operations using Azure Cosmos DB

Click Create button.

Deployment started initialized in a minute or two this became successful.

 CRUD Operations using Azure Cosmos DB

Click the Go to Resource button.

Click the Data Explorer option on the left-hand side of the menu.

 CRUD Operations using Azure Cosmos DB

In the Data Explorer window, click the New Container option.

Type Database id as retail on the Data Explorer window.

 CRUD Operations using Azure Cosmos DB

Choose Autoscale as the Database throughput option.

Choose Database Max RU/s as 1000 and then type Container Id as an employee.

Maintain the indexing type as an Automatic option.

Type the Partition key as /employeeId.

 CRUD Operations using Azure Cosmos DB

Finally, click the Ok button.

 CRUD Operations using Azure Cosmos DB

Now you can see in the Data Explorer window retail as databases and employees as containers.

 CRUD Operations using Azure Cosmos DB

Create Operation

Click New Item on the Data Explorer window either the users can type the input or upload the file on the Upload item option.

 CRUD Operations using Azure Cosmos DB

Here the users started typing the input in the format of JSON and then save the item on the Data Explorer window.

 CRUD Operations using Azure Cosmos DB

Once the users clicked the Save item button automatically, some of the fields generated by Azure Cosmos DB like _self, _etag, and _rid.

 CRUD Operations using Azure Cosmos DB

Update Operation

Suppose the user wants to update some of the fields in the Azure Cosmos DB account.

It's very simple. Just by clicking the Edit items, the users can perform the Update operation easily with one click.

Before the Update operation, you notice that the city value was Chennai.

 CRUD Operations using Azure Cosmos DB

After the Update operation, the value of the city field was updated to Mumbai.

 CRUD Operations using Azure Cosmos DB

Delete Operation

Consider the scenario the user wants to remove a particular field or particular record. Is it possible in Azure Cosmos DB?

It's easy. Just click Delete Item on the Data Explorer window.

The user wants to delete record 103 on the Data Explorer window.

 CRUD Operations using Azure Cosmos DB

Immediately a pop-up window will appear on the screen to check whether you want to select an item or not.

The users will get a confirm delete option to perform the operation delete it or not.

 CRUD Operations using Azure Cosmos DB

Successfully deleted the record 103 on the Azure Cosmos DB and look the outcome of the final record.

 CRUD Operations using Azure Cosmos DB

Read Operation

The users want to explore the read operation on the Data Explorer window.

Just by clicking the New query on the window.

Type any query in the Query section, which is displayed on the screen.

 CRUD Operations using Azure Cosmos DB

The final outcome will be displayed in the Results section.

 CRUD Operations using Azure Cosmos DB

The users want to use dot notation in the query section. Is it possible in the Azure Cosmos DB?

Yes, it is possible to use dot notation on the Data Explorer Window.

 CRUD Operations using Azure Cosmos DB

Similarly, the users can use the bracket notation on the Azure Cosmos DB query.

 CRUD Operations using Azure Cosmos DB

Summary

In this article, we learned and created successfully an Azure Cosmos DB account creation, High-level architecture. Also, we created and deployed the different types of  CRUD operations using Azure Cosmos DB end-to-end deployment. Most of the customers started using Azure Cosmos DB. Its globally distributed and easy to store the data in the JSON format.

Thanks for reading this article!!

Happy Learning!!!