In this blog, we are going to create Azure Cosmos DB with Core(SQL) as API. Understand data explorer, create document database from data explorer, insert dummy data and use .net SDK to read data from Cosmos DB.
Let us start by creating Azure Cosmos DB for Core(SQL)
Login to Azure portal, click on Create a resource and search for Cosmos DB. Selecting Azure Cosmos DB will navigate to the Create screen.

The create action will navigate to the create wizard, The create wizard has 5 steps, lets navigate through each step and understand the purpose and select appropriate options.
Step Basics :
This step has the basic information like subscription, instance details, API’s, Primary Location, Account Type, Geo Redundancy, multi-region writes.
Subscription : An Azure subscription is a logical container used to provision resources in Azure. It serves as a single billing unit for Azure resources
Resource Group : It is a container that holds related resources for an Azure solution
API : The Azure Cosmos DB REST API provides programmatic access to Azure Cosmos DB resources to create, query, and delete databases, document collections, column family and graphs.
Notebooks : (Microsoft definition) Cosmic notebooks are available for all data models and APIs including Cassandra, MongoDB, SQL (Core), Gremlin, and Spark to enhance the developer experience in Azure Cosmos DB. These notebooks are directly integrated into the Azure Portal and your Cosmos accounts, making them convenient and easy to use. Developers, data scientists, engineers and analysts can use the familiar Jupyter notebooks experience to:
- Interactively run queries
- Explore and analyze data
- Visualize data
- Build, train, and run machine learning and AI models
Geo Redundancy : The geographic redundancy service replicates data between two geographically distant sites so that applications can switch from one site to another
Multi-region writes : The writes will be distributed across regions, in case of catastrophic failure of one, the data can be replicated from other multi-region list.
In the following screen print, i am leaving all the settings as default and creating new resource group tweaknosqlrg and giving Account Name as tweakadmin and move on to second step in the wizard.

Step Networking :
You can choose from the following 3 options, to either access your Cosmos DB account publicly or provide access to selected networks or using Private endpoint. The default option is All networks. I choose to restrict access to my Cosmos DB to selected networks only. This will prompt me to create Virtual Network and add subnet IP’s to access this account. I named my vnet as tweakvnet and assigned all the available IP’s to my subnet.


Step Encryption :
I will select the default option of Service managed key.

Step Tags :
To categorize, i am create env tags as per the following screen print.

Step Review + create :
On clicking review and create, the wizard will check for any validation errors.

Allow between 5-10 mins for the deployment to finish.

Once the deployment is finished, click on resources and select the resource group which was created for this account. We will see Cosmos DB and Vnet created for us.

Clicking on tweakadmin will navigate to Azure Cosmos DB landing page. There are lot of feature and services to explore on left navigation. In this post we will only be using Data Explorer to create containers and inserting data manually.

To create a container, you can either click on add container on header controls or click on Data Explorer in left navigation. I clicked on Data Explorer in left navigation and selected New Container. The Add container template will prompt to enter Database id, Container id and Partetion Key. Lets see in definition on what these option mean to us.
Database id : A database is analogous to a namespace. A database is the unit of management for a set of Azure Cosmos containers. I am naming my Database id as tweakcosmosforsql
Containers : An Azure Cosmos container is the unit of scalability both for provisioned throughput and storage. A container is horizontally partitioned and then replicated across multiple regions. The items that you add to the container and the throughput that you provision on it are automatically distributed across a set of logical partitions based on the partition key. I am naming my container as people.
Partetion Key : This key ensure the uniqueness of one or more values in a logical partition

Our container is created, we can insert dummy data if we do not already have one. lets click on items>> New Item to insert dummy data. I have dummy data created in advance, this can be downloaded from the blog. I am pasting my json in new item section hitting on save.


Now we have data inserted into our container. The following screen shot illustrates what we discussed above. tweakcosmosforsql is the database which we have created, people is the container which holds people json and city is the partition. The records with Brisbane as city will be under one partition and other cities with similar name will be grouped under different partition.

So far we saw how to create Core(SQL) api, create containers from Data Explorer and insert records into database. If you want to connect to Cosmos db from say .NET SDK, you will be not able to connect because, in setp 2 Networking of create Cosmos db wizard, we selected Selected networks option and assigned tweakvnet IP’s so that no other IP’s from Internet can access my resource including my client IP, to facilitate this i have to navigate to firewall and virtual networks and add my client IP to the list of selected networks list.

Now that we have everything created and configured to play with around. Its is time to read the data from .NET SDK. Create new Console application from Visual Studio and install the following package.
Install-Package Microsoft.Azure.Cosmos
After installation, This client library enables client applications to connect to Azure Cosmos via the SQL API. All it takes was to create a Cosmos Client, get Cosmos client database, get client database container and read the data from the container. The code to read the data is as follows. The code will be available for download at the end of this blog.

Summary :
We have created Azure Cosmos DB for Core(SQL), create database container, inserted dummy date through Data explorer and used .NET SDK to read data from Azure Cosmos DB.
Happy learning!