Azure Cosmos Db – Part three – Working with the Azure DocuementDB

 ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​​​ Understanding the Azure Document DB

Azure Document Db is a Document based No SQL subset of CosmosDb, so if you’re not familiar with them I request you to go through my articles​​ here​​ and​​ here.

Azure DB is a subset of​​ Azure DocumentDB is schema-free and combines rich and familiar SQL query capabilities with consistent low latencies on JSON-based data models, targeting solutions for web, mobile, gaming, and IoT. Since DocumentDB is schema agnostic, it makes it extremely easy to adjust and adapt data models on the fly as business logic and application scenarios change. With DocumentDB you no longer have to deploy constant updates to the data-tier and worry about managing schema and relationships. All content in DocumentDB is automatically indexed, which makes it possible to query data across entire structures at any time. The term “NoSQL” is more of a marketing buzzword, and actual means “no requirement for entity relationships and secondary indexing” in order to query information.

Since DocumentDB is a JSON-based storage mechanism, accessing and interacting with data can be accomplished through most standards-based interfaces, as well as robust toolsets and SDKs. Although native Universal Windows Platform support is not currently available, support for virtually any other development scenario is available. Deeper level features of are currently exposed via JavaScript, such as stored procedures, triggers and user defined functions (UDFs) making it easy for developers to write application logic that can be packaged and executed directly on database storage partitions.






Terminologies related to DocumentDb






A database is a logical container of document storage partitioned across collections. It is also a users container.


The logical namespace for scoping permissions.


An authorization token associated with a user for access to a specific resource.


A collection is a container of JSON documents and the associated JavaScript application logic.

Stored Procedure

Application logic written in JavaScript which is registered with a collection and transactionally executed within the database engine.


Application logic written in JavaScript executed before or after either an insert, replace or delete operation.


Application logic written in JavaScript. UDFs enable you to model a custom query operator and thereby extend the core DocumentDB query language.


Arbitrary user-defined JSON content. By default, no schema needs to be defined nor do secondary indices need to be provided for all the documents added to a collection.


Hands On Demo

We are trying to create a MVC application and showcase the simple CRUD operations with Cosmos DB.

  • Go to Azure Portal and search for cosmos db.


  • You will get 4 Options Gremlin, MongoDb, SQL (DocumentDB) and Table (keyValue Pair). As we are working with DocumentDb so we are going to select the documentdb option and supply the necessary information like the resource group and where do you want to host your db.  ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​ ​​​​