SAY “HELLO” TO AZURE COSMOS DB

In this step-by-step tutorial I will show you how to create Azure Cosmos DB and how to integrate it with ASP.NET MVC Web Application.

While creating New Cosmos DB you will get 4 API options:

  • Gremlin,
  • MongoDB,
  • SQL(DocumentDB),
  • Graph

Here, we will select DocumentDB and fill-out other information like Resource Group and Region of the data center where you want to host it.

Once the Cosmos DB account is created, Go to the quick start option in the properties menu and then click on Create Items Collection Button. This will create a Collection in the database and then download the sample application.

Open your project in Visual Studio and go to web .config.

You will get the endpoint, the authKey, Database and Collections are populated with the information from your cosmosdb.

If you’re developing your application from scratch then you need to pass on this information to your web .config.

The Item Collection that we have created has a corresponding controller in our MVC application sample and it contains most of the common CRUD scenarios covered and its calling the documentdb repository in its actions Items.


Going to the DocumentDbRepository which acts as an interface between our application and the documentdb. It’s has all the definitions of Crud operations in the database and it also takes care of creating a new db/collection if they don’t exist by doing a sanity check.


I want you to understand the few line of code here which is not plain C# but has to do with the understanding of the documentDb.

The above lines are creating a data base and creating a collection Inside it but here its also setting the throughput of the Database which means how many request can a database can handle concurrently. Here we are mentioning the throughput as 1000.

The billing cost of the database is directly proportional to the throughput of the database so please make sure that you’re handling it properly and the minimum throughput is 400 that’s set by Microsoft for the documentDb Database.

Let’s go to the Data Explorer on the azure portal and if you’re an existing customer of Document Db you might realize that with moving under the CosmosDb hood, the have improved the data explorer.