Steps to create cosmos db from azure subscription

This article outlines the steps to create Cosmos DB from the azure subscription.

  1. Login to azure portal – Click on Azure Cosmos DB – Create Cosmos DB
  2. Type the document ID – keep this in mind this document ID is the URL we will be using  as connection string in the application.
  3. Select the preferred API according to your requirement.
  4. Choose the azure subscription, select the resource group
  5. Choose the primary location where the data needs to be replicated.There is an option to enable geo redundancy which can be done later as well.

https://exchangequery.files.wordpress.com/2018/04/picture9.png?w=600

To Enable Geo-Redundancy-

Click on – Enable Geo Redundancy – and choose the  preferred region.

https://exchangequery.files.wordpress.com/2018/04/picture10.png?w=600

Replicate data globally in few clicks –

https://exchangequery.files.wordpress.com/2018/04/picture11.png?w=600

Failover options –

There are 2 failover options Manual and automatic.

https://exchangequery.files.wordpress.com/2018/04/picture12.png?w=600
Manual can be triggered any time – we just need to select the disclaimer and initiate failover.

https://exchangequery.files.wordpress.com/2018/04/picture13.png?w=600

Add new regions any time and replicate our data in few minutes-

https://exchangequery.files.wordpress.com/2018/04/picture14.png?w=600

Failover options – Automatic

we need to go and enable the automatic failover as below

https://exchangequery.files.wordpress.com/2018/04/picture15.png?w=600

Also there is an option to change the priorities of the failover in few clicks.Good part is can be done any time and we do not need to change them on the code.

https://exchangequery.files.wordpress.com/2018/04/picture16.png?w=600

Consistency levels:

Can be modified and altered any time. The default consistency type is session as below.

https://exchangequery.files.wordpress.com/2018/04/picture17.png?w=600

Network Security for the Database:

We have an option to access the database only from few subnets. This gives a complete security to the document. A VAPT can be initiated after setting up this security which eases the database admin job on considerations on data security.

https://exchangequery.files.wordpress.com/2018/04/picture18.png?w=600

Endpoint and Keys to integrate with our code:

We need to use the URI and the primary key to integrate with the code. This can be seen by clicking on the keys section on the left side.

https://exchangequery.files.wordpress.com/2018/04/picture19.png?w=600

Summary:

Now a Cosmos Database is created  –  now create new Collection-  create documents –  Then they are stored in JSON rows. Try to have most of the  documents under one collection, because the pay model is per collection.

Create collection:

Click on Add collection

https://exchangequery.files.wordpress.com/2018/04/picture21.png?w=1200&h=310

Create new Database ID – then Collection ID

Remember the collections in Cosmos DB are created in the below order.

https://exchangequery.files.wordpress.com/2018/04/picture23.png?w=600

Now we need to choose the throughput and the storage capacity. They will be charged according to the selection. Also there is an option to choose unique keys which adds more data integrity.

https://exchangequery.files.wordpress.com/2018/04/picture22.png?w=600

Example of a new document

https://exchangequery.files.wordpress.com/2018/04/picture25.png?w=600

Better to define a document ID and collection ID.

https://exchangequery.files.wordpress.com/2018/04/picture241.png?w=600

Once the above is done, we can connect via preferred available API  to our document and the developer do not need to worry about data schema , indexing, security.

More sample codes in GitHub:

https://github.com/Azure-Samples/azure-cosmos-db-documentdb-nodejs-getting-started

Example below:

Before we can run this sample, we must have the following prerequisites:

◦An active Azure Cosmos DB account.
◦Node.js version v0.10.29 or higher.
◦Git.

1) Clone the repository.

https://exchangequery.files.wordpress.com/2018/04/picture26.png?w=600
2) Change Directories.
3) Substitute Endpoint with our primary key and endpoint.

https://exchangequery.files.wordpress.com/2018/04/picture27.png?w=600
4) Run npm install in a terminal to install required npm modules
5) Run node app.js in a terminal to start our start our node application