Documentdb Tutorial
Documentdb Tutorial
DocumentDB is Microsoft's newest NoSQL document database platform that runs on Azure.
DocumentDB is designed keeping in mind the requirements of managing data for latest
applications. This tutorial explains the basics of DocumentDB with illustrative examples.
Audience
This tutorial is designed for beginners, i.e., for developers who want to get acquainted
with how DocumentDB works.
Prerequisites
It is an elementary tutorial that explains the basics of DocumentDB and there are no
prerequisites as such. However, it will certainly help if you have some prior exposure to
NoSQL technologies.
All the content and graphics published in this e-book are the property of Tutorials Point (I)
Pvt. Ltd. The user of this e-book is prohibited to reuse, retain, copy, distribute or republish
any contents or a part of contents of this e-book in any manner without written consent
of the publisher.
We strive to update the contents of our website and tutorials as timely and as precisely as
possible, however, the contents may contain inaccuracies or errors. Tutorials Point (I) Pvt.
Ltd. provides no guarantee regarding the accuracy, timeliness or completeness of our
website or its contents including this tutorial. If you discover any errors on our website or
in this tutorial, please notify us at [email protected].
i
Table of Contents
About the Tutorial .................................................................................................................................... i
Audience .................................................................................................................................................. i
Prerequisites ............................................................................................................................................ i
1. DOCUMENTDB – INTRODUCTION........................................................................................ 1
DocumentDB – ........................................................................................................................................ 2
Pricing ..................................................................................................................................................... 2
Endpoint ............................................................................................................................................... 22
Create a Database for DocumentDB using the Microsoft Azure Portal .................................................. 27
Relationships......................................................................................................................................... 85
iii
21. DOCUMENTDB – PARTITIONING...................................................................................... 114
iv
1. DOCUMENTDB – INTRODUCTION
In this chapter, we will briefly discuss the major concepts around NoSQL and document
databases. We will also have a quick overview of DocumentDB.
There are different types of NoSQL databases which include key value stores such as:
Azure DocumentDB
Microsoft officially launched Azure DocumentDB on April 8th, 2015, and it certainly can be
characterized as a typical NoSQL document database. It's massively scalable, and it works
with schema-free JSON documents.
It also delivers consistently fast reads and writes, schema flexibility, and the ability
to easily scale a database up and down on demand.
It does not assume or require any schema for the JSON documents it indexes.
5
DocumentDB enables complex ad-hoc queries using a SQL language, and every
document is instantly queryable the moment it's created, and you can search on any
property anywhere within the document hierarchy.
DocumentDB – Pricing
DocumentDB is billed based on the number of collections contained in a database account.
Each account can have one or more databases and each database can have a virtually
unlimited number of collections, although there is an initial default quota of 100. This quota
can be lifted by contacting Azure support.
A collection is not only a unit of scale, but also a unit of cost, so in DocumentDB you
pay per collection, which has a storage capacity of up to 10 GB.
As your database grows in size and exceeds 10 GB, you'll need to purchase another
collection to contain the additional data.
Each S1 collection will give you 250 request units per second, and if that's not
enough, then you can scale the collection up to an S2 and get a 1000 request units
per second for about $50 a month.
You can also turn it all the way up to an S3 and pay around $100 a month.
6
2. DOCUMENTDB – ADVANTAGES
DocumentDB stands out with some very unique capabilities. Azure DocumentDB offers the
following key capabilities and benefits.
Schema Free
In a relational database, every table has a schema that defines the columns and data types
that each row in the table must conform to.
In contrast, a document database has no defined schema, and every document can be
structured differently.
SQL Syntax
DocumentDB enables complex ad-hoc queries using SQL language, and every document is
instantly queryable the moment it's created. You can search on any property anywhere within
the document hierarchy.
Tunable Consistency
It provides some granular, well-defined consistency levels, which allows you to make sound
trade-offs between consistency, availability, and latency.
You can select from four well-defined consistency levels to achieve optimal trade-off between
consistency and performance. For queries and read operations, DocumentDB offers four
distinct consistency levels:
Strong
Bounded-staleness
Session
Eventual
Elastic Scale
Scalability is the name of the game with NoSQL, and DocumentDB delivers. DocumentDB has
already been proven its scale.
Major services like Office OneNote and Xbox are already backed by DocumentDB with
databases containing tens of terabytes of JSON documents, over a million active users,
and operating consistently with 99.95% availability.
You can elastically scale DocumentDB with predictable performance by creating more
units as your application grows.
7
Fully Managed
DocumentDB is available as a fully managed cloud-based platform as a service running on
Azure.
Microsoft does all that work and keeps the service running.
Within literally minutes, you can get started working with DocumentDB using just a
browser and an Azure subscription.
8
3. DOCUMENTDB – ENVIRONMENT SETUP
Microsoft provides a free version of Visual Studio which also contains SQL Server and it can
be downloaded from https://www.visualstudio.com/en-us/downloads/download-visual-
studio-vs.aspx.
Installation
Step 1: Once downloading is completed, run the installer. The following dialog will be
displayed.
9
Step 2: Click on the Install button and it will start the installation process.
10
11
Step 3: Once the installation process is completed successfully, you will see the following
dialog.
12
Step 4: Close this dialog and restart your computer if required.
Step 5: Now open Visual studio from start Menu which will open the below dialog. It will take
some time for the first time only for preparation.
Once all is done, you will see the main window of Visual Studio.
13
Step 6: Let’s create a new project from File -> New -> Project.
14
Step 7: Select Console Application, enter DocumentDBDemo in the Name field and click OK
button.
15
End of ebook preview
If you liked what you saw…
Buy it from our store @ https://store.tutorialspoint
16