Getting Started With Azure DocumentDB: Day 1

What is DocumentDB

DocumentDB

DocumentDB is a fully managed, highly scalable, query-able, truly schema-free JSON document database, delivered as a service for modern applications.

Azure DocumentDB is a NoSQL document database service designed from the ground up to natively support JSON and JavaScript directly inside the database engine.

Why

  • Produce and consume data at a staggering rate while requiring near instantaneous response times to much user expectations.
  • Increasingly complex, compensating for the lack of query and transactional processing in today’s NOSQL database system.
  • Experience unpredictable and explosive growth.

What is a database account

A database account holds a set of databases, each database can containing multiple collections so every collection can contain stored procedure, triggers and related documents, JSONfiles.

NoSQL

Azure DocumentDB is a NoSQL document database service, support JSON and JavaScript directly inside the database engine.

DocumentDB is designed for modern mobile and web applications. Azure DocumentDB supports querying using a SQL language.

NoSQL document

To use Azure DocumentDB, you must have a DocumentDB account, a database, a collection, and documents. So for this, simply go to Microsoft Azure login page and login with your account.

login

After the “Sign in”, go to “Home” and click on to “Portal”. After clicking on the portal you will see the following window. For DocumentDB you have to do:

Step 1: Click on “New” button.

Step 2: Scroll down and select “Data+Storage”.

Step 3: Again scroll down and you will see “Azure DocumentDB”, Click on it.

After clicking on the “Azure DocumentDB” you will automatic jump on the DocumentDB account. This will ask to you for the “ID”.

Azure DocumentDB

Give the “ID” name here, Id name is simply your “DocumentDB account” name what you want to use for further operations. Here I gave it “nitindocdb”, you can give any name here what you want. Make sure ID name cannot contain / \ #? or space between the words.

When your name is validated, this will mark a green check.

In the “Resource Group” you can choose the “Default- SQL-EastAsia”, this is nothing but your location where you are going to use this account.

In the “Location” section you can choose your location.

After this, hit on the “Create” button.

hit on Create button

Here in the following figure, I have successfully created my DocumentDB account with name “nitindocdb".

Here you can see different types of operations like settings, Add Database, Document Explorer, Query Explorer, Script Explorer, Import Data, Move and Delete Account.

Click on key button (shown in middle red rectangle), you can see in the right side of the window it holds “URI” and “Keys”. URI and Keys are the particular information of the DocumentDB account.

DocumentDB account

Now, I’m going to create a database.

After clicking on my account name, which I created “nitindocdb”, we will redirect on the next database window.

Click on “Add Database”.

Add database

After clicking on the “Add Database” this will redirect in to new window, and again ask for “ID”, here “ID” is your database name, so in the “ID” section give the database name which is you want to use, here I gave “docdatabase” name to my database.

Hit on “OK” button.

Hit on OK button

Now you can see I have created a database with name “docdatabase”.

docdatabase

Now we need to add Collection.

Collections are the transaction boundary for stored procedures and triggers, and the entry point to queries and CRUD operations.

Click on the “docdatabase” which I have created just and it will redirect you to new window, here you can see the “Add Collection” option.

Hit on “Add Collection”.

In the next window it will again ask for the “ID”, here “ID” is your collection ID, give the name in “ID” section, here I gave “Record” name to my collection.

Click on “OK” button.

Record

I have created a collection, click on it.

Click on the “Record” collection and you can find “Add Documents” in the next window.

In the next window you can add the records and documents in the collection section. We can add any record or documents in the collection section.

records and documents

It will redirect to next page, here you can upload 100 JSON documents, but make sure document must be less than 512kb. To upload JSON documents click on the red rectangle.

Select a file

Here I have selected two JSON files, animal.json and info.json with extension of json.
Click on “Upload” button.
Click on Upload

So, here I had successfully uploaded two files, you can see the result is succeeded.

Add Document

Now, go to the “Document Explorer” to check your uploaded files. Click on “Document Explorer” it will redirect you to the document explorer window.

You can see, there are two json files ID, it creates the file in the format of “ID” by default.

View, create, and edit documents with Document Explorer

Document Explorer allows you to easily create, edit and delete documents. I’ m going to edit my document, click on any one to edit.

Document Explorer

I’m going to edit top Id, click on it, you will see the code of the JSON, scroll down and in the “ID” section give the name to “ID” whatever you want. Here I gave “Nitin”, and then click on to “Save” button.

After clicking on “Save” button, you can see in the left side of the window, the Id name will be changed.

You can edit everything in the document section whatever you want, after edit the document, click on save button it will be changed.

document

Now, I’m going to create a document.

To create a document, simply click the “CreateDocument” command and a minimal JSON snippet is provided.

Create document

If you do not provide an "id" property, then Document Explorer automatically adds an id property and generates a GUID as the id value.

Simply type the JSON content of the document you wish to create and click on “Save” command, to commit your document.

click on Save

The changes can be seen in the left side of the window, with “Nitin Pandit” ID.

Save document

By the Delete command, you can delete the existing record, let’s do it, I have record with default ID, click on Delete command to delete this document.

click on Delete

Click on “Yes” button.

The document will be deleted.

Click on Yes

So, I had successfully deleted previous record and now only two collections are remaining.

deleted previous record
Thanks for reading this article. In the next article we’ll learn how to perform queries on documents in Azure. So stay tuned for my next article, “How to perform Query in DocumentDB in the portal of Azure."