Inserting Data into Cosmos DB Using ASP.NET Core API

In this article, we will learn how to insert the data into the Azure Cosmos DB with SQL API using the ASP.NET Core API. Let's learn step by step.

Step 1: Set up Prerequisites

To perfrom the insert  operation in the Azure Cosmos DB we are required the following one the of the Prerequisites.

  • Azure Subscription OR
  • Azure Cosmos DB Emulator 

Azure Subscription 

To create the Azure cloud Cosmos DB account, you need an active Azure subscription. When you create the Cosmos DB account on the cloud, the Azure Cosmos DB Serverless account provides the first 1000 RU and 25 GB of storage for free per subscription.

Refer to the following link to learn the basics and how to create the Azure Cosmos DB account.

Azure Cosmos DB Emulator (offline)

As explained, the first approach requires an active Azure subscription as well as an active internet connection, which is not feasible for everyone who just wants to explore or learn about the Azure Cosmos DB.

To overcome the preceding issue, we can use the Azure Cosmos DB capabilities and features using the Azure Cosmos DB Emulator without an active Azure subscription or an active internet connection.

The Azure Cosmos DB Emulator currently does not have support for all the NoSQL API's, but it will support the most commonly used NoSQL API's such as the SQL API and Mongo DB API, and in the future it may also support all the Cosmos DB API's.

The following is the link to download the Azure Cosmos DB Emulator.

After clicking on the link, the official Microsoft documentation website gets opened, from which you can find and install the latest version of the Azure Cosmos DB Emulator.

Step 2: Create Azure Cosmos DB 

In this article, we are going to use the Azure Cosmos DB emulator instead of a Cloud Azure Cosmos DB account. If you are a beginner, then please refer to the following articles to learn how to create an Azure Cosmos DB account.
We are using the Azure Cosmos DB emulator in this article. search for the Azure Cosmos DB emulator from the search bar of the window once you download and install the emulator, which looks like the following:



The preceding image shows the Azure CosmosDB Account of the emulator, which will provide the same features as the Cloud Azure CosmosDB Account for development. Now click on the explorer and create the database and container. The explorer will then look like this:



We are storing the employee basic data in the Azure CosmosDB, and we are planning to use Department as a partition key and ID as the unique id for our employee records.

Note:
  • The ID and Department properties should be part of your backend input while inserting or updating the records; otherwise, you will get the exceptions.
I hope you have completed the required setup as explained in this article, including the creation of the Azure Cosmos account and database.

Step 3: Create ASP.NET Core web api Project

  1. Start then  All Programs and select "Microsoft Visual Studio".
  2. Once the Visual Studio Opens, Then click on Continue Without Code.
  3. Then Go to Visual Studio Menu, click on File => New Project then choose ASP.NET Core Web Api Project Template.
  4. Then define the project name, location of the project, then click on the next button.
  5. On the next screen, provide the additional details: framework, authentication type, and check the Enable Open API Support checkbox as shown below.


The preceding steps will create the ASP.NET Core Web API application and solution explorer. It will look like what is shown in the following image.



Step 4: Add Microsoft.Azure.Cosmos Nuget Package Reference

The Microsoft.Azure.Cosmos is the the latest nuget package to interact with the Azure cosmos DB. The Microsoft.Azure.Cosmos supports the basic to custom and complex database operations, follow the following steps to add the Nuget package.

  1. Right click on the Solution Explorer, find Manage NuGet Package Manager and click on it
  2. After as shown into the image and type in search box Microsoft.Azure.Cosmos
  3. Select Microsoft.Azure.Cosmos as shown into the image, 
  4. Choose version of Microsoft.Azure.Cosmos library and click on install button


I hope you have followed the same steps and installed the Microsoft.Azure.Cosmos nuget package.The next step is to delete the default controller and model class so we can start from scratch.


Step 5:Create the Model Class

  • First, delete the default model class, which is created outside the folder structure, so we can start from scratch. 
  • Next, create the folder named Model by right clicking on the solution explorer.
  • Create the model class Employee Model by right clicking on the Model folder, as shown in the following image


Now open the EmployeeModel.cs class file and add the following code.

EmployeeModel.cs

namespace EmployeeManagement.Model
{
    public class EmployeeModel
    {
        public string? id { get; set; }
        public string? Name { get; set; }
        public string? Country { get; set; }
        public string? City { get; set; }       
        public string? Department { get; set; }
        public string? Designation { get; set; }
        public DateTime? JoiningDate { get; set; }

    }
}

Step 6: Add the Controller

Create the Empty API Controller class EmployeeController by right clicking on the Controller folder as shown in the following image.



After adding the model class and API controller class, the solution explorer will look like the following:




Now open the EmployeeController.cs file and add the add the following configuration.
  • Define the following route at controller level, so that we can add the multiple Get, Post, Put, or Delete and avoid the name ambiguity exception.
    [ApiController]
    [Route("[api/[controller]/[action]]")]
    public class EmployeeController : ControllerBase
    {
    }

  • Declare the following variable and set the Azure Cosmos DB configuration by copying the details from step 2.
    [ApiController]
    [Route("api/[controller]/[action]")]
    public class EmployeeController : ControllerBase
    {
       
        // Cosmos DB details, In real use cases, these details should be configured in secure configuraion file.
        private readonly string CosmosDBAccountUri = "https://localhost:8081/";
        private readonly string CosmosDBAccountPrimaryKey = "C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==";
        private readonly string CosmosDbName = "EmployeeManagementDB";
        private readonly string CosmosDbContainerName = "Employees";
}

Step 7: Create Method to Add Employee

Add the following code into the EmployeeController.cs class to Add the employees into the CosmosDB. This method takes input values using  the EmployeeModel class. 

        [HttpPost]
        public async Task<IActionResult> AddEmployee(EmployeeModel employee)
        {
            try
            {
                var container = ContainerClient();
                var response = await container.CreateItemAsync(employee, new PartitionKey(employee.Department));

                return Ok(response);
            }
            catch (Exception ex)
            {

                return BadRequest(ex.Message);
            }
               
        } 



As explained in step 2, we are passing the ID and Department as a partition key as part of the employee input payload while adding the employee details. These parameters must be part of the input parameter payload.

The entire code of the EmployeeController.cs class file will look like the following after adding all the methods together:

EmployeeController.cs

using EmployeeManagement.Model;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.Cosmos;

namespace EmployeeManagement.Controllers
{
    [ApiController]
    [Route("api/[controller]/[action]")]
    public class EmployeeController : ControllerBase
    {
       
        // Cosmos DB details, In real use cases, these details should be configured in secure configuraion file.
        private readonly string CosmosDBAccountUri = "https://localhost:8081/";
        private readonly string CosmosDBAccountPrimaryKey = "C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==";
        private readonly string CosmosDbName = "EmployeeManagementDB";
        private readonly string CosmosDbContainerName = "Employees";


        /// <summary>
        /// Commom Container Client, you can also pass the configuration paramter dynamically.
        /// </summary>
        /// <returns> Container Client </returns>
        private  Container  ContainerClient()
        {

            CosmosClient cosmosDbClient = new CosmosClient(CosmosDBAccountUri, CosmosDBAccountPrimaryKey);
            Container containerClient = cosmosDbClient.GetContainer(CosmosDbName, CosmosDbContainerName);
            return containerClient;
           
        }


        [HttpPost]
        public async Task<IActionResult> AddEmployee(EmployeeModel employee)
        {
            try
            {
                var container = ContainerClient();
                var response = await container.CreateItemAsync(employee, new PartitionKey(employee.Department));

                return Ok(response);
            }
            catch (Exception ex)
            {

                return BadRequest(ex.Message);
            }
               
        }

    }
}

Now, we have all the code and required configuration to work with Azure CosmosDB in our sample application.

Step 8: Run the ASP.NET Core API Application

Now press Keyboard F5 or the Visual Studio Run button to run the application. After running the application, the following screen will be shown in the browser with swagger UI having all the methods which we have created in our ASP.NET core web API, as shown in the following screenshot:




Now, we will test the functionality by using the Swagger UI, but you can use Postman or any other tool to execute the API endpoints.

Step 9: Azure Cosmos DB Data Insert Demo 

The following animated image shows how the data gets added to the Azure Cosmos DB with SQL API.

Add Employees


Summary

Cosmos DB Free Tier Limitations

In this article, I will explain how to use the Azure Cosmos DB free tier and the limitations of the Azure Cosmos DB free tier plan. The Azure Cosmos DB free tier enables a developer or learner to quickly get started, test or learn about the Azure Cosmos DB, and even deploy test applications.

The free tier discount can be used in the following two ways:

  • Azure Cosmos DB Free Tier (paid or corporate subscription)
  • Azure Free Account (Free Azure Account for Learners )

The Azure Cosmos DB Free Tier and the Azure Free Account are two different things. The Azure Cosmos DB Free Tier is typically associated with corporate or paid subscriptions, whereas the Azure Free Account is a Microsoft offering that allows users to learn about Azure Services by creating a free account for a limited time or for the duration of the subscription.

The Cosmos DB free tier discount can be applied during the creation of the Cosmos DB account. During account creation, the following options will be available, as shown in the following image:


Azure Cosmos DB Free Tier Limitations and Features

  • The Azure Cosmos DB free tier discount is only supported in provisioned throughput capacity mode.
  • This free discount is not yet supported in the serverless capacity mode.
  • The discount can be applied to only one Cosmos DB account per subscription, meaning you cannot apply the discount to two Cosmos DB accounts in the same subscription.
  • The dedicated throughput is not supprted since the throughput is shared across all the containers in the database.
  • The maximum of 1000 RU per second is supported on the database level, which can be shared across containers.
  • The maximum of 25 GB of storage is free per account, along with the first 1000 RU/s.
  • The maximum of 25 containers created per database is similar to the normal account, but the limit for the free discount is that the throughput is shared across all the containers.
  • Beyond 1000 RU/s and the maximum storage capacity, the normal charges are applied.
  • If you create a free Azure account, you will receive combined benefits for the first 12 months, which means you will receive 400 RU/s of free Azure account and 1000 RU/s for Azure Cosmos DB free tier disccount, totaling 1400 RU/s for the first 12 months, after which the regular Azure free account limits will apply.
  • The same combined benefits are applied for the storage. You will get the 25 GB of Azure free account and the 25 GB of Cosmos DB free tier discount, which combined are 50 GB for 12 months. After the 12 months, the normal limits are applied for the lifetime of your free Azure account.

I hope, from all the examples above, you have learned how to use the Azure Cosmos DB free tier and the limitations of the Azure Cosmos DB free tier plan. I. If you like it, share it with your friends and subscribe to the blog and YouTube channel for more articles.

Creating Azure Cosmos DB Using Azure Portal

In this article, we will learn how to create the Azure Cosmos DB using the Azure Portal. So let's start creating the Cosmos DB service step by step.

Prerequisites

You need a valid Azure subscription either free or paid to create any service in the Azure, I hope you have a valid subscription.

What is Azure Cosmos DB?

Azure Cosmos DB is the NoSQL database which is a globally distributed and highly available database. The Azure Cosmos DB stored the data in the JSON format. The database is easily scalable by a few clicks across the regions.

Step 1: Login To Azure Portal

Navigate to the portal.azure.com using a browser and login into the portal with valid credentials, as shown in the following image.

After a successful authentication, the page will be redirected to the Azure portal default dashboard page as shown in the following image.

 Step 2:  Create the Azure Cosmos DB

Find the create resource option which can be found left top side of the portal as shown into the following image or follow any other option which you may know to create the resource (service) in the Azure portal. Search for the Azure Cosmos DB as shown in the following image.


As shown in the preceding image, click on the create button, it will show the following screen.


Provide the required details as shown in the preceding image

Subscription

Choose the available Azure subscription which you want to use for creating the service from the drop down list.

Resource Group

Choose an existing resource group or create a new resource group which you may want to use.

Account Name

Provide the unique name for the Azure Cosmos database account which creates the universal unique URI by appending the Cosmos database service URL.

API

Azure Cosmos database provides the five API's which decide what type of data is stored into the cosmos DB. The following are the API's.

  • SQL API
  • Cassandra API
  • Gremlin API
  • Table API
  • MongoDB API
In our article we are using the SQL API.

Location

Choose the deployment location for Azure Cosmos database from the given list.

Capacity Mode

The capacity mode decides the processing capacity for your database which are as

  • Provisioned throughput 
  • Serverless

The database operation cost also differs depending on the selected capacity mode.

Apply Free Tier Discount

You can decide whether to apply or not to apply the free tier discount. If you apply the free tier discount, you will get the first 400 RU/s and 5 GB of storage for free in an account.

Account Type

The Azure Cosmos database allows users to choose the following two account types.

  • Production
  • Non-production

If your application is running in the production environment, then choose the Production account type; otherwise, choose the non-production account type. This is only the azure resource tag which does not impact on any cost-related things on your Cosmos database account.

Geo-redundancy

You can enable the disable of your account global distribution by pairing with the other region. This makes sure that your database account will be globally replicated along with another region.

Multi-region Writes

The Azure Cosmos DB is capable of writing the data on the multiple regions. If you want to write the data to multiple regions, then just enable the button, otherwise keep it in disable mode.

After providing all the required basic details, click on the next button, then the networking screen will get appeared where you can define the networking details as shown in the following image.


As shown in the preceding image, you can decide from which network the Azure Cosmos database is available to connect that is either public network or private network or both the networks.

Now after providing the required networking details, click on the next Backup policy option, then the following screen will appear where you can define the Backup policy details.


You can choose the backup policy, how frequently database backup can be taken by using the periodic or Continuous option, as shown in the preceding image.

Now after providing the required backup policy details, click on the Next Encryption button, then the following screen will appear where you can define the encryption details.


As shown in the preceding image, choose how data is encrypted that is either using the service managed key or customer managed key.

Once you choose the data encryption method, click on the next step tags, which will show the following screen.


The tagging helps to identify or categorize the services across the line of applications. After providing the tag details, click on the next step, Review and Create, then the following screen will get appeared to review the details before creating the service.


After reviewing details, click the create button, it will take some time to create the service. Once the service is created, the status can be notified on the notification icon. Now click on the Go to resource button, you will be redirected to the newly created Azure Cosmos database service.

The Azure Cosmos database welcome screen will look like as shown in the following image from which you can manage your Azure cosmos database.


Step 3: Create the DataBase and Container.

In previous steps we have created the Azure Cosmos database account. Now we need to create the database and a container to store the data. Use the data explorer option as shown in the following image.


As shown in the preceding image, HumanResource is the database id and EmployeeMaster is the Container Id. These two terms are equivalent to the database name and table name respectively in a relational database.

The Database throughput decides the request-proceesing capacity for your database which you can choose between the Manual and Autoscale. Choose the manual for this article and keep 400 RU/s (request units per second), which is the default. We have chosen Partition Key as departmentName which can logically distribute the data on the multiple servers which makes database operation faster, each partition key has 20 GB of capacity.

I hope you have provided the required details as explained in the preceding, now click the Ok button, then it will create the database and container as shown in the following image.


Step 4: Adding the New Item

Now we have a Database and Container Id, let's add the item (records) into it as steps shown in the following image.


Now use the preceding document structure and click on the save button. After saving the document, it will look like as follows.


As you can see in the preceding image, what the added document structure looks like, Cosmos DB will add some auto-generated properties which can be mostly useful during the database operation.

Summary

I hope from the preceding explanation you have learned how to create the cosmos database and add the document.

Related Articles

Now Azure Cosmos DB Support Partial Document Update

The Microsoft announced the most awaited and productive feature for Azure Cosmos DB in the Build 2021 event that is to update the partial document in the Azure Cosmos DB.

Previously, the developer needed to call the whole document in the program and replace the entire document even for a single field update. This process involved the round trip to the server. This process consumes lots of request units for each request which directly impact on cost increase.

The partial update document feature is available for Core (SQL) API using the .NET SDK, Java SDK and stored procedures. The developer can sign up for a private preview using the following link to test the applications.

Related article

I hope this post is useful to get early access to the feature and test your application. If you like this article, then share with your friends and subscribe to the blog.

Now Azure Cosmos DB Free Tier Supports 25 GB Storage and 1000 Ru/s

In the MS Build 2021 event, Microsoft announced the limit enhancement of Azure Cosmos DB. Now Azure Cosmos DB will support 25 GB of storage and 1000 request units per second (1000 Ru/s) for every month per subscription, which is increased from previously 5 GB of storage and 400 request units per second (400 Ru/s) per subscription.

You can use this free tier by simply creating the free tier Cosmos DB account or just applying the free tier discount. If you know more how to create the Azure Cosmos DB, then please refer to the following link.


The limit enhancement will help developers to test their small application workloads very effectively in the development environment..

Read more details by using the following link.

Summary

Microsoft Azure enhancing their platform in a very short time to enhance the user experience and productivity, I hope you will test your applications effectively with the limit enhancement.

Getting Started with Azure Cosmos DB

In this article, we will learn about the Azure Cosmos DB. So let's learn about Azure Cosmos DB  step by step.

Prerequisites

You need a valid Azure subscription either free or paid to create any service in the Azure, I hope you have a valid subscription.

What is Azure Cosmos DB?

Azure Cosmos DB is the NoSQL database which is a globally distributed and highly available database. The Azure Cosmos DB stored the data in the JSON format. The database is easily scalable by a few clicks across the regions.

Now let's learn about the Cosmos DB while creating the instance into the Azure portal. So you can visualize and understand the concepts easily.

Step 1: Login To Azure Portal

Navigate to the portal.azure.com using a browser and login into the portal with valid credentials, as shown in the following image.

After a successful authentication, the page will be redirected to the Azure portal default dashboard page as shown in the following image.

 Step 2:  Create the Azure Cosmos DB

Find the create resource option which can be found left top side of the portal as shown into the following image or follow any other option which you may know to create the resource (service) in the Azure portal. Search for the Azure Cosmos DB as shown in the following image.


As shown in the preceding image, click on the create button, it will show the following screen.


Provide the required details as shown in the preceding image

Subscription

Choose the available Azure subscription which you want to use for creating the service from the drop down list.

Resource Group

Choose an existing resource group or create a new resource group which you may want to use.

Account Name

Provide the unique name for the Azure Cosmos database account which creates the universal unique URI by appending the Cosmos database service URL.

API

Azure Cosmos database provides the five API's which decide what type of data is stored into the cosmos DB. The following are the API's.

  • SQL API
  • Cassandra API
  • Gremlin API
  • Table API
  • MongoDB API
In our article we are using the SQL API for the demonstration.

Location

Choose the deployment location for Azure Cosmos database from the given list. It will always be better to choose the location which is close to your customer's location.

Capacity Mode

The capacity mode decides the processing capacity for your database which are as

  • Provisioned throughput 
  • Serverless

The database operation cost also differs depending on the selected capacity mode.

Apply Free Tier Discount

You can decide whether to apply or not to apply the free tier discount. If you apply the free tier discount, you will get the first 400 RU/s and 5 GB of storage for free in an account.

Account Type

The Azure Cosmos database allows users to choose the following two account types.

  • Production
  • Non-production

If your application is running in the production environment, then choose the Production account type; otherwise, choose the non-production account type. This is only the azure resource tag which does not impact on any cost-related things on your Cosmos database account.

Geo-redundancy

You can enable the disable of your account global distribution by pairing with the other region. This makes sure that your database account will be globally replicated along with another region.

Multi-region Writes

The Azure Cosmos DB is capable of writing the data on the multiple regions. If you want to write the data to multiple regions, then just enable the button, otherwise keep it in disable mode.

After providing all the required basic details, click on the next button, then the networking screen will get appeared where you can define the networking details as shown in the following image.


As shown in the preceding image, you can decide from which network the Azure Cosmos database is available to connect that is either public network or private network or both the networks.

Now after providing the required networking details, click on the next Backup policy option, then the following screen will appear where you can define the Backup policy details.


You can choose the backup policy, how frequently database backup can be taken by using the periodic or Continuous option, as shown in the preceding image.

Now after providing the required backup policy details, click on the Next Encryption button, then the following screen will appear where you can define the encryption details.


As shown in the preceding image, choose how data is encrypted that is either using the service managed key or customer managed key.

Once you choose the data encryption method, click on the next step tags, which will show the following screen.


The tagging helps to identify or categorize the services across the line of applications. After providing the tag details, click on the next step, Review and Create, then the following screen will get appeared to review the details before creating the service.


After reviewing details, click the create button, it will take some time to create the service. Once the service is created, the status can be notified on the notification icon. Now click on the Go to resource button, you will be redirected to the newly created Azure Cosmos database service.

The Azure Cosmos database welcome screen will look like as shown in the following image from which you can manage your Azure cosmos database.


Step 3: Create the DataBase and Container.

In previous steps we have created the Azure Cosmos database account. Now we need to create the database and a container to store the data. Use the data explorer option as shown in the following image.


As shown in the preceding image, HumanResource is the database id and EmployeeMaster is the Container Id. These two terms are equivalent to the database name and table name respectively in a relational database.

The Database throughput decides the request-proceesing capacity for your database which you can choose between the Manual and Autoscale. Choose the manual for this article and keep 400 RU/s (request units per second), which is the default. We have chosen Partition Key as departmentName which can logically distribute the data on the multiple servers which makes database operation faster, each partition key has 20 GB of capacity.

I hope you have provided the required details as explained in the preceding, now click the Ok button, then it will create the database and container as shown in the following image.


Step 4: Adding the New Item

Now we have a Database and Container Id, let's add the item (records) into it as steps shown in the following image.


Now use the preceding document structure and click on the save button. After saving the document, it will look like as follows.


As you can see in the preceding image, what the added document structure looks like, Cosmos DB will add some auto-generated properties which can be mostly useful during the database operation.

Summary

I hope from the preceding explanation you have learned about the Azure Cosmos Database. If you have any suggestion, then you can send it using the comment box.

Related Articles

Introduction To Azure CosmosDB

In this article, we will learn about the Azure Cosmos DB. So let's learn about Azure Cosmos DB  step by step.

Prerequisites

You need a valid Azure subscription either free or paid to create any service in the Azure, I hope you have a valid subscription.

What is Azure Cosmos DB?

Azure Cosmos DB is the NoSQL database which is a globally distributed and highly available database. The Azure Cosmos DB stored the data in the JSON format. The database is easily scalable by a few clicks across the regions.

Now let's learn about the Cosmos DB while creating the instance into the Azure portal. So you can visualize and understand the concepts easily.

Step 1: Login To Azure Portal

Navigate to the portal.azure.com using a browser and login into the portal with valid credentials, as shown in the following image.

After a successful authentication, the page will be redirected to the Azure portal default dashboard page as shown in the following image.

 Step 2:  Create the Azure Cosmos DB

Find the create resource option which can be found left top side of the portal as shown into the following image or follow any other option which you may know to create the resource (service) in the Azure portal. Search for the Azure Cosmos DB as shown in the following image.


As shown in the preceding image, click on the create button, it will show the following screen.


Provide the required details as shown in the preceding image

Subscription

Choose the available Azure subscription which you want to use for creating the service from the drop down list.

Resource Group

Choose an existing resource group or create a new resource group which you may want to use.

Account Name

Provide the unique name for the Azure Cosmos database account which creates the universal unique URI by appending the Cosmos database service URL.

API

Azure Cosmos database provides the five API's which decide what type of data is stored into the cosmos DB. The following are the API's.

  • SQL API
  • Cassandra API
  • Gremlin API
  • Table API
  • MongoDB API
In our article we are using the SQL API for the demonstration.

Location

Choose the deployment location for Azure Cosmos database from the given list. It will always be better to choose the location which is close to your customer's location.

Capacity Mode

The capacity mode decides the processing capacity for your database which are as

  • Provisioned throughput 
  • Serverless

The database operation cost also differs depending on the selected capacity mode.

Apply Free Tier Discount

You can decide whether to apply or not to apply the free tier discount. If you apply the free tier discount, you will get the first 400 RU/s and 5 GB of storage for free in an account.

Account Type

The Azure Cosmos database allows users to choose the following two account types.

  • Production
  • Non-production

If your application is running in the production environment, then choose the Production account type; otherwise, choose the non-production account type. This is only the azure resource tag which does not impact on any cost-related things on your Cosmos database account.

Geo-redundancy

You can enable the disable of your account global distribution by pairing with the other region. This makes sure that your database account will be globally replicated along with another region.

Multi-region Writes

The Azure Cosmos DB is capable of writing the data on the multiple regions. If you want to write the data to multiple regions, then just enable the button, otherwise keep it in disable mode.

After providing all the required basic details, click on the next button, then the networking screen will get appeared where you can define the networking details as shown in the following image.


As shown in the preceding image, you can decide from which network the Azure Cosmos database is available to connect that is either public network or private network or both the networks.

Now after providing the required networking details, click on the next Backup policy option, then the following screen will appear where you can define the Backup policy details.


You can choose the backup policy, how frequently database backup can be taken by using the periodic or Continuous option, as shown in the preceding image.

Now after providing the required backup policy details, click on the Next Encryption button, then the following screen will appear where you can define the encryption details.


As shown in the preceding image, choose how data is encrypted that is either using the service managed key or customer managed key.

Once you choose the data encryption method, click on the next step tags, which will show the following screen.


The tagging helps to identify or categorize the services across the line of applications. After providing the tag details, click on the next step, Review and Create, then the following screen will get appeared to review the details before creating the service.


After reviewing details, click the create button, it will take some time to create the service. Once the service is created, the status can be notified on the notification icon. Now click on the Go to resource button, you will be redirected to the newly created Azure Cosmos database service.

The Azure Cosmos database welcome screen will look like as shown in the following image from which you can manage your Azure cosmos database.


Step 3: Create the DataBase and Container.

In previous steps we have created the Azure Cosmos database account. Now we need to create the database and a container to store the data. Use the data explorer option as shown in the following image.


As shown in the preceding image, HumanResource is the database id and EmployeeMaster is the Container Id. These two terms are equivalent to the database name and table name respectively in a relational database.

The Database throughput decides the request-proceesing capacity for your database which you can choose between the Manual and Autoscale. Choose the manual for this article and keep 400 RU/s (request units per second), which is the default. We have chosen Partition Key as departmentName which can logically distribute the data on the multiple servers which makes database operation faster, each partition key has 20 GB of capacity.

I hope you have provided the required details as explained in the preceding, now click the Ok button, then it will create the database and container as shown in the following image.


Step 4: Adding the New Item

Now we have a Database and Container Id, let's add the item (records) into it as steps shown in the following image.


Now use the preceding document structure and click on the save button. After saving the document, it will look like as follows.


As you can see in the preceding image, what the added document structure looks like, Cosmos DB will add some auto-generated properties which can be mostly useful during the database operation.

Summary

I hope from the preceding explanation you have learned about the Azure Cosmos Database. If you have any suggestion, then you can send it using the comment box.

Related Articles

www.CodeNirvana.in

Protected by Copyscape
Copyright © Compilemode