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
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/)
Search for Azure Cosmos DB service in the global search bar and then click.
Click the Azure Cosmos DB account button.
Select Azure Cosmos DB for the NoSQL option and then click Create button.
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.
Click Review+ Create button on the basics tab.
You will get the Validation Success message which is appeared on the screen.
Click Create button.
Deployment started initialized in a minute or two this became successful.
Click the Go to Resource button.
Click the Data Explorer option on the left-hand side of the menu.
In the Data Explorer window, click the New Container option.
Type Database id as retail on the Data Explorer window.
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.
Finally, click the Ok button.
Now you can see in the Data Explorer window retail as databases and employees as containers.
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.
Here the users started typing the input in the format of JSON and then save the item on the Data Explorer window.
Once the users clicked the Save item button automatically, some of the fields generated by Azure Cosmos DB like _self, _etag, and _rid.
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.
After the Update operation, the value of the city field was updated to Mumbai.
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.
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.
Successfully deleted the record 103 on the Azure Cosmos DB and look the outcome of the final record.
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.
The final outcome will be displayed in the Results section.
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.
Similarly, the users can use the bracket notation on the Azure Cosmos DB query.
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!!!