In this article, we will create a JSON document under cosmos DB collection through the portal and will also check how we can create it through C#.
Please go through my previous articles of this series,
- Introduction To Azure Cosmos DB - Day One
- Quick Start With Azure Cosmos DB - Day Two
- Quick Start With Azure Cosmos DB - Day Three
Create Document through Azure Portal
Log in to the Azure portal
Select Azure Cosmos DB and expand your database; i.e., Recharge
Navigate to Documents under the 'Prepaid' collection.
Click on 'New Document' which will allow writing documents in JSON format,
For each document 32 big GUID ID is assigned. You can save documents up to the size of 2 MB. Each document can be of a different schema as it is schema free.
Create Document through Azure Portal
Create one console application in Visual Studio.
Add NuGet package Microsoft.Azure.DocumentDB
Define the model having all the fields which we want to persist under cosmos DB.
- class Transaction
- {
- public string id { get; set; }
- public string Operator { get; set; }
- public string Provider { get; set; }
- public string Region { get; set; }
- public string Mobile { get; set; }
- public string Amount { get; set; }
- public string Status { get; set; }
- public string ExecutionTime { get; set; }
- public DateTime CreatedDate { get; set; }
- public Transaction()
- {
- }
- }
In order to create a document, first we need to connect to cosmos DB which requires the below details:
- EndpointUrl - URL created by Azure with account name which is provided by us; i.e., utilitybillpayments
- AuthorizationKey - Generated by Azure for the account
- Database Name - In our case we have given 'Recharge'
- Collection Name - In our case we have given 'Prepaid'

SG PatelPosted Oct 5, 2018, 1:21 AM
You make it essay for me. Thank you for such nice article.