Learn Microsoft DocumentDB – Fully managed NoSQL Database offering for Azure Platform

Yesterday Microsoft Azure services took a big leap forward by announcing their fully managed Cloud based NoSQL Database Service named as “DocumentDB” which will run under Azure Cloud Computing Platform.

What is NoSQL database

NoSQL database is a different category of database where you have no schema defined for records. Essentially every record may have same or very different number of attributes (i.e. columns). Each record can have nested attributes (in traditional RDBMS this is done by Normalizing Entity into Multiple Tables). OK enough to start with NoSQL .. you can Bing it to find more..

What is DocumentDB

DocumentDB is Microsoft latest offering in already crowded NoSQL database market. So question is why Microsoft created another Database System? Here is the list of handful facts about  DocumentDB which makes it very appealing compared to other NoSQL Database vendors out there

  • DocumentDB provides Transaction support for Schema Free documents
  • DocumentDB is created to offer rich T-SQL like query language which most of Database developer know. This is an outstanding feature which is lacking in most of NoSQL database out there
  • DocumentDB provides Modern Javascript as T-SQL which runs on server.
  • DocumentDB provides handle on Consistent Read vs Non-Consistent Read
  • DocumentDB uses proprietary In Memory technology called Hekaton for very fast query.
  • DocumentDB is fully managed service under Azure Platform …means no deployment .. no hassle… Everything is managed by Azure Platform behind the scene for you.
  • DocumentDB is fully accessible via .Net SDK, PHP SDK, Python SDK, Node.js .. All of them are open source.
  • You may access DocumentDB using simple RESTful HTTP Calls in any programming language without any SDK.
  • Pay as you go model…. makes it possible to try NoSQL technology in few clicks.
  • Fully scalable.. easily add or remove Compute units as needed. 
  • Support for Stored Procedures
  • Support for Triggers
  • Support for Userdefined functions .. You can easily call them in you sql query

How to get started with DocumentDB – NoSQL Database

DocumentDB is in Preview and you can try it now and learn more about it. Right now DocumentDB is only available under Azure Preview portal (This is new Azure Portal which is under Preview). Classic Azure Portal (Old version) doesn’t list DocumentDB yet.

Once you login to Preview Portal perform the following step to create your very first NoSQL database under Azure DocumentDB

  1. Click on Plus sign at the bottom
  2. Click on Everything and expand to to see all categories.
  3. Select Data, Storage, Cache+backup category
  4. on next page select DocumentDB (By Microsoft)
  5. When prompted click on Create
  6. Select domain name prefix for your account URL. such as  mycomanycloud.documents.azure.com
  7. Once done hit create and wait for a min or so… This will DocumentDB for you.

create-azure-documentdb-nosql-database

create-azure-documentdb-nosql-database-2

create-azure-documentdb-nosql-database-3

DocumentDB SQL Query Examples

 Here is sample query examples which you can submit to your DocumentDB. This is very unique feature to Microsoft NoSQL offering. Most of NoSQL database I worked doesn’t allow to write SQL like query…. This is awesome!!!

--////////////////  Simple Select Query With Where Clause
SELECT * 
FROM Families f 
WHERE f.id = "AndersenFamily"

--////////////////  Extracting elements as JSON Fragments 
SELECT {"Name":f.id, "City":f.address.city} AS Family 
FROM Families f 
WHERE f.address.city = f.address.state

--//////////////// JOIN Example
SELECT c.givenName 
FROM Families f 
JOIN c IN f.children 
WHERE f.id = 'WakefieldFamily'

--//////////////// User defined function
SELECT GetSalesTax(item, 'US') FROM item in cart.items

For FULL reference Click here

You can try their online demo here  http://www.documentdb.com/sql/demo

How to Query DocumentDB records in .Net using LINQ

Here is an example how to query DocumentDB records in .net using OpenSource SDK available (download from  nuget , or github)

var query = (IDocumentQuery)client.CreateDocumentQuery(collectionLink)  
.SelectMany(team => team.Members.Where(member => member.Age >= 18))
var results = await query.ExecuteNextAsync();

 

How to get .Net samples for DocumentDB

1. Download – C# Sample Code for DocumentDB : http://code.msdn.microsoft.com/Azure-DocumentDB-NET-Code-6b3da8af

2. Install nuget Package.. from here. http://www.nuget.org/packages/Microsoft.Azure.Documents.Client/

If you dont know how to install NuGet Packages in VS2012 … then follow these steps.. http://docs.nuget.org/docs/start-here/Using-the-Package-Manager-Console

3. After extracting sample… Make sure to change appSettings.config before running samples. To set your account EndPoint URI (example:  https://youraccount.documents.azure.com:443/ ) and your Access Key (Look under Azure Portal and Click DocumentDB —> Keys ) 

 

NOTE: You must set your C# Project to use .net Framework 4.0 or  Higher in order to add these client libraries. It will add 2 dlls to your project reference. Microsoft.Azure.Documents.Client.dll and Newtonsoft.Json.dll

Sample Code includes various samples for following  

  • How to Create DocumentDB Database in C# code
  • How to Create DocumentDB Index in C# code
  • How to Create DocumentDB Collection (i.e. Tables) in C# code
  • How to Manage DocumentDB Users
  • How to Query records using Linq and SQL Query language of DocumentDB

DocumentDB Reference Links

Azure DocumentDB Reference Documentation :  http://msdn.microsoft.com/en-us/library/azure/dn781482.aspx
Getting Started with DocumentDB: http://azure.microsoft.com/en-us/documentation/articles/documentdb-get-started/
Nuget Package for DocumentDB .Net Client : http://www.nuget.org/packages/Microsoft.Azure.Documents.Client/
C# Code Sample: http://code.msdn.microsoft.com/Azure-DocumentDB-NET-Code-6b3da8af
DocumentDB Blog Entry: Introducing DocumentDB
DocumentDB Tutorial : http://www.documentdb.com/sql/tutorial
DocumentDB Live Demo: http://www.documentdb.com/sql/demo

 

 

Binary World is a Software Development company located in Atlanta, USA (since 2007). Binary World specialized in Business Intelligence, mobile, cloud computing and .Net Application Development.

Tagged with: , , ,
Posted in Big Data, Cloud Computing, NoSQL, Windows Azure