Creating Azure Cosmos DB Resources From The Azure Portal

Introduction

CosmosDB is Microsoft provided database service that can suit any kind of application like web, IOT or gaming, etc., which requires massive read, write, and processing of data. Due to its indefinite capacity of handling data CosmosDB has become one of the sought-after Azure services of all time. Internally, just like any other non-relational database engines (mongodb, Cassandra etc.,) maintains all the data in an optimized storage model like Key-value, Graph or Document stores.

Advantages

There are many advantages that CosmosDB provides to its applications, some of them are listed below.

  • Multiple APIs - With multiple APIs you can access the data stored in other mediums like SQL Core API, Cassandra, MongoDB, Gremlin, and Azure Table Storage. It also provides an easy way to migrate the data into CosmosDB.
  • Scalability - For all unprecedented spikes in the workload to modify the structure anytime by adding or removing Azure regions to your cosmosdb account.
  • Availability - Regional failover for cosmosdb account databases is possible which helps Microsoft to provide up to 5 nine’s – 99.999% availability.
  • Secure - It has row level authorization as well as keeps the data encrypted at rest in motion.

Creating Azure CosmosDB

To begin with creating cosmosdb through azure portal, follow the instructions as per point number 01 and 02 given in the screenshot. At 01 type cosmosdb to go to the database creation page and click on create button.

Creating Azure Cosmos DB resources from the Azure portal

When you click on create you will be asked to choose the API which you would like to select. I have selected Core (SQL) for this demo.

Creating Azure Cosmos DB resources from the Azure portal

In the next window provide with the name and the highlighted part ‘Capacity Mode’ relates to how you will be billed.

CosmosDB is available in two different capacity modes: Provisioned throughput and Serverless. You can perform the exact same database operations in both modes, but the way you get billed for these operations will be different.

On the tabs followed by the Basics, you will have many options related to enabling encryption, backup policy, redundancy and multi-region writes.

The Quick Start page is the first you will see once you have created the CosmosDB resource. You can add a container where the data will be stored, the container can handle 400 request units per second throughput. But for now, we will not create the container here, I will show where this can be done manually which will have the option to change the RU/s as per our need.

Now go to the overview page to see the endpoint URI that you can use to connect the database. Below is the connection URI for my cosmosdb database.

https://firstcosmos040722.documents.azure.com:443/

Creating Azure Cosmos DB resources from the Azure portal

The multi region option if enabled helps you to select the regions in which you want to replicate your data to provide faster reads to your clients placed anywhere in the world.

Creating Azure Cosmos DB resources from the Azure portal

Container

The CosmosDB account is ready and now we can go ahead and create database under this account and add containers. Go to Data Explorer tab on left side and click on New Container option, here provide name for the database under which the container will be created.

Creating Azure Cosmos DB resources from the Azure portal

Important thing to note here is you can create multiple containers per database or can choose an existing database to create your containers. CosmosDB can share the throughput provisioned to the database across all the containers within the database thereby cutting down the costs. For demo purpose, I will keep the throughput to the default 400 RU/s (request units per second).

Provide unique name for the DatabaseID and other options like automatic index all data to gain performance access and the partition key that can be used for logically partitioning within the same container.

To add a new Item, you can create from the same Data Explorer tab and then use the sample query as given below.

Creating Azure Cosmos DB resources from the Azure portal

{
    "id": "1",
    "category": "personal",
    "name": "groceries",
    "description": "Pick up apples and strawberries.",
    "isComplete": false
}

I inserted 3 records just for the purpose of this demo. We can see those records when you click on the items field under the container.

Query the data

The easiest way is to open a new query and execute the SQL to fetch the query results. You can use advanced SQL as per your needs to filter out the records based on your requirements.

Creating Azure Cosmos DB resources from the Azure portal

In addition to the results, you will also have an option to check out the stats which includes the time taken for each step and partition data saved into CSV which is downloadable.

Creating Azure Cosmos DB resources from the Azure portal

Summary

In this article, we checked how to create your first cosmosdb database with container and how to read and write data into it. This is the first article on Azure CosmosDB, will try to add up more topics in the coming days.


Similar Articles