Kick Start With Azure Cosmos DB

In this article, we will discuss Azure Cosmos DB. We will answer questions such as: What is a Cosmos DB? Why do we need to use the Cosmos DB? We will also learn how to create a new Azure Cosmos DB account using Azure subscriptions, how to create a new database and collection using Azure, and how to add data to the collection.
 
In this article, we will see the following,
  • What is Azure Cosmos DB?
  • Why do we need to use the Cosmos DB?
  • How to create a new Azure Cosmos DB account using Azure
  • How to create a new database and collection using Azure
  • How to add data to the collection using Data Explorer
  • How to use SQL Query to the collection using Data Explorer
  • How to get Cosmos DB connection string from Azure
Prerequisite
  • Azure Subscriptions

What is Azure Cosmos DB?

 
Azure Cosmos DB is a globally distributed database service. It supports multi-model approaches such as the document, Key/Value, wide columns and graph databases using APIs.
 
The list of APIs such as the following:
  • SQL API
  • MongoDB API
  • Graph API
  • Table API
  • Cassandra API

Why do we need to use the Cosmos DB?

 
Azure Cosmos DB is offering the following items:
  • Global distributions
  • Elastic scale out
  • Guaranteed low latency
  • Five consistency models
  • Comprehensive SLAs

How to create a new Azure Cosmos DB account using Azure

 
You can learn in this section, how to create a new Azure cosmos database account using the Azure portal with the following guidelines.
Go to open the new browser, you can copy and paste the following URL
 
 
Then, sign in to the Azure portal using Microsoft Account credentials:
 
 
 
After successfully logging into the Azure portal, you can see the dashboard looks like the following screenshot.
 
 
 
You can go to create a resource-Databases - click the Azure Cosmos DB.
 
 
 
The Azure Cosmos DB new account window will be opened and you can enter the following details, which are required. Then, click the Create button.
  • ID
  • API
  • Subscription Name
  • Resource Group Name
  • Location
The list of API options is available in the following screenshot:
 
 
 
Now, you can see the notification window displaying the deployment in progress notification. Once it is completed you will get the deployment succeeded notification in the notification window. Then, click the go to resource button.
 
 
 
 
After successfully creating the Azure Cosmos DB account, the Congratulations! Your Azure Cosmos DB account was created window will be opened, as in the following screenshot.
 
 
 

How to create a new database and collection using Azure

 
You will learn in this section, how to create a new database and collection in Data Explorer using Azure portal.
 
You can go to Data Explorer - click the New Collections
 
 
 
The Add Collection window will be opened and you can enter the following details, which are required. Then, click the OK button.
  • Database Id
  • Collection Id
  • Storage Capacity
  • Throughput
 
You can see the new database and collection looks at the following screenshot.
 
 
 

How to add data to the collection using Data Explorer

 
You can learn in this section, how to add sample data to the collection in Data Explorer using Azure portal at the following guidelines.
You can go to Data Explorer - Expand the Table collection in the Collection window, click the Documents - click the New Document.
 
 
 
The new document window will be opened and add the data to the collection with the following format.
 
 
  1. {  
  2.    “Id”: “1”,  
  3.    “TableName”: “Table A”,  
  4.    “Location”: “Front Row”,  
  5.    “Status”: “Available”,  
  6.    “Date”: “28-02-2018”  
  7. }  
Once you have added json data to the document, click the Save button.
 
 
 
After successfully added records to the collection it looks like the following screenshot:
 
 
 

How to add SQL Query to the collection using Data Explorer

 
You can learn in this section, how to use SQL query to the collection in Data Explorer using Azure portal at the following guidelines.
You can go to Data Explorer - Expand the Table collection in the Collection window, click the New SQL Query
 
 
 
The Query window will be opened as in the below screenshot
 
 
 
Once you have executed query by clicking Execute Query button:
 
 
 
You can use the Where condition and Order By for the select statement on SQL Query window in the Azure Cosmos DB as in the below screenshots:
 
 
 
 

How to get Cosmos DB connection string from Azure

 
You will learn in this section, how to get the Cosmos DB connection string in Keys using the Azure portal.
 
You can go to Settings - click the Keys
 
 

Now you can copy the URI and Primary Key into your web.config file in your project

Conclusion

 
I hope you understand now about Azure Cosmos DB, how to create a new Azure Cosmos DB account using Azure, how to create a new database and collection using Azure, how to add data to the collection using Data Explorer, how to use SQL Query to the collection using Data Explorer and how to get Cosmos DB connection string from Azure. I have covered all the required things. If you find anything missing, please let me know.
 
Reference
  • https://docs.microsoft.com/en-us/azure/cosmos-db/
  • http://www.san2debug.net/post/kick-start-with-azure-cosmos-db.aspx 
Please share your valuable comments or feedback to improve my future articles. 
 


Similar Articles