Azure DocumentDB – CRUD Operations

Started playing around with Azure DocumentDB, and I am pretty excited about it. The simplicity is just crazy. Most of the application out there need CRUD operations, So I thought I will try to compile them in 1 post for quick reference.

  • To begin with you need to create a DocumentDB database account. The below link walks through that.

https://azure.microsoft.com/en-us/documentation/articles/documentdb-create-account/

  • Next step is to create DocumentDB collections, which will hold our documents.
  • Next step is to add documents into the collections. Following link explains how to add, view documents using the document explorer, we will look how to do them using the sdk.
  • Next step is to get the DocumentDB client library package to start coding against Azure DocumentDB.

  • Next create a DocumentClient , from which we will execute all our CRUD operations.

You can find the DocumentDB URI and primary key from the azure portal.

docdb1

  •  Once we have a DocumentClient we are ready to work with collections. To work with collections we need to get the collection link, the easiest way to find the selflink for the collection is to use a tool called DocumentDB Studio .

docdb2

Copy the selflink as part of your configuration.

As application developer we work with entities and objects and their json serialized formats, Azure DocumentDB is designed from the ground up to natively support JSON and JavaScript directly inside the database engine, which makes application development much more agile.  You can download the simple console application here which covers all the basic CRUD operations on Azure  DocumentDB. Also for quick reference, below is the code.

  •  Resources