Creating and Querying Microsoft Azure DocumentDB
DocumentDB is the latest storage option added to Microsoft Azure.
It is a no-sql storage service that stores JSON documents natively and provides indexing capabilities along with other interesting features.
the Microsoft Technet Wiki.
Contributor awards on the 12th of October 2014.
DocumentDB is the latest storage option added to Microsoft Azure.
It is a no-sql storage service that stores JSON documents natively and provides indexing capabilities along with other interesting features.
This wiki shall introduce you to this new service.
Setting up a Microsoft Azure DocumentDB
Go to the new Microsoft Azure Portal. https://portal.azure.com/
Click on New > DocumentDB
Enter A Database ID and hit Create!
Please wait while the database is being created.
After the database is created, Keys button to get the Database URI and its required keys.
We may now start building our App.
Using Microsoft Azure DocumentDB in your Application
Create project
Create a new project and add the nuget package Microsoft Azure DocumentDB Client Library.
Go to Tools > Package Manager > Package Manager Console.
Key in Install-Package Microsoft.Azure.Documents.Client -Pre and hit enter.
Define the Model
Add the endpoint url and the authorization key.
These values are same values identified above.
Create a new instance of the DocumentClient
It is used to configure and execute requests against the service.
Create Database
This will return an instance of a database, first creating it if it doesn’t already exist.
Create a document collection
This method returns a document collection, creating it if it doesn’t already exist.
A document collection is a named logical container for documents.
The method CreateDocumentCollectionQuery creates and returns a query for document collections.
Create Documents
Create normal c# objects that represent documents.
Save the documents
The document is now saved.
You may now browse it from the Azure portal. From the dashboard, select your DocumentDB, scroll down to Document Explorer, and select the collections you wish to view.
Read data from the Application
You can use both SQL and LINQ to retrieve data in DocummentDB.
Using SQL
Retrieving one team
Retrieving all teams:
Using LINQ
Retrieving one team:
Retrieving all teams:
}
Updating a document
You first need to get the document to update, make the changes and replace the document.
Delete a document
Conclusion
Microsoft Azure DocumentDB is really easy to use and allows for rapid application development.
Being able to store heterogeneous JSON documents within DocumentDB and query it using SQL like syntax and LINQ is really great which means that the developer do not have to learn anything new.
This service is still in preview mode and will get even more interesting with time.
Also, since it is still in preview mode, the materials presented in this wiki may change in the future.