• 7 min read

10 GitHub samples with Azure DocumentDB you shouldn’t miss!

Azure DocumentDB is a fully managed, multi-model, scalable, queryable, schema-free NoSQL database service built for modern applications: mobile, web, IoT, bots, AI, etc. Recently, I went on GitHub…

As of May 10th 2017,

Azure Cosmos DB is Microsoft’s globally distributed multi-model database. Azure Cosmos DB was built from the ground up with global distribution and horizontal scale at its core. It offers turnkey global distribution across any number of Azure regions by transparently scaling and replicating your data wherever your users are. Elastically scale throughput and storage worldwide, and pay only for the throughput and storage you need. Azure Cosmos DB guarantees single-digit-millisecond latencies at the 99th percentile anywhere in the world, offers multiple well-defined consistency models to fine-tune performance, and guarantees high availability with multi-homing capabilities—all backed by industry leading service level agreements (SLAs). 

Azure Cosmos DB is truly schema-agnostic; it automatically indexes all the data without requiring you to deal with schema and index management. It’s also multi-model, natively supporting document, key-value, graph, and column-family data models. With Azure Cosmos DB, you can access your data using APIs of your choice, as DocumentDB SQL (document), MongoDB (document), Azure Table Storage (key-value), and Gremlin (graph) are all natively supported.

Azure DocumentDB is a fully managed, multi-model, scalable, queryable, schema-free NoSQL database service built for modern applications: mobile, web, IoT, bots, AI, etc. Recently, I went on GitHub and have found a lot of useful material and links to step-by-step tutorials and examples. Below are the top 10 that anyone starting to build an app backed by planet-scale NoSQL should know about. There is lots more. So head on over and learn about this cool new NoSQL planet-scale database service.

1. Azure/azure-documentdb-dotnet

In this repo, you can find the samples and utilities relating to Azure DocumentDB and the .NET SDK and how to use them. The samples demonstrate how to use every method and operation of the .NET SDK, and searchabletodo is a sample ASP.NET MVC web application that shows how to build an ASP.NET MVC web application with DocumentDB and then further enrich it with Azure Search. Another great example in this repo is a Xamarin sample which illustrates how to use DocumentDB built-in authorization engine to implement per-user data pattern for a Xamarin mobile app. It is a simple multi-user ToDo list app allowing users to login using Facebook Auth and manage their to do items. After playing with this sample, you can then go further with Xamarin and build any IoS or Android app on top of DocumentDB.

The samples will walk you through how to best interact with the service using Client SDK. Specifically:

  • CollectionManagement – shows CRUD operations on DocumentCollection resources.
  • DatabaseManagent – shows CRUD operations on Database resources.
  • DocumentManagement – shows CRUD operations on Document resources.
  • IndexManagement – shows samples on how to customize the Indexing Policy for a Collection should you need to.
  • Partitioning – included samples for common partitioning scenarios using the .NET SDK.
  • Queries –  shows how to query using LINQ and SQL.
  • ServerSideScripts – shows how to create and execute Stored Procedures, Triggers and User Defined Functions.
  • UserManagement – shows CRUD operations on User and Permission resources.
  • Spatial – shows how to work with GeoJSON and DocumentDB geospatial capabilities.

After walking through these samples, you should have a good idea of how to get going and how to make use of the various APIs interacting with the NoSQL service in Azure.

2. mingaliu/DocumentDBStudio

This repo contains DocumentDBStudio –  a client management viewer/explorer for DocumentDB service. Currently it supports:

  1. Easy browsing of DocumentDB resources, which enables you to learn DocumentDB resource model very quickly.
  2. Create, Read, Update, Delete (CRUD) and Query operations for every DocumentDB resources and resource feed.
  3. Support of SQL or UDF query. You can execute Javascript stored procedure or trigger right from DocumentDBStudio.
  4. Inspection of headers (for quota, usage, RG charge, etc.) for every request operation. It also supports three connection modes: TCP, HTTPDirect, and Gateway.
  5. Support of various RequestOptions (for pre/post trigger, sessionToken, consistency model etc), FeedOptions(for paging, enableScanforQuery etc), IndexingPolicy (for indexingMode, indexingType, indexingPath etc).
  6. PrettyPrint the output JSON.
  7. Bulk import of JSON files.

It is simply a “good IDE” for the “natives” of DocumentDB. Give it a try.

3. Azure/azure-documentdb-node

This repo provides a Node.js module that makes it easy to interact with Azure DocumentDB using Node.js – an open-source, cross-platform JavaScript runtime environment suited for developing a diverse variety of tools and applications. Node.js aims to optimize throughput and scalability in Web applications with many input/output operations, as well as for real-time Web applications (e.g., real-time communication programs and browser games). Combining it with DocumentDB service gives you a really powerful combination and agility in building up an app and then scaling it up very quickly.

If you are developing using Node.js and combining it with DocumentDB, see Node.js Developer Center and the Microsoft Azure DocumentDB Node.js SDK Documentation. Also, to get started, watch this YouTube video. The samples in the repo were built using the Node.js Tools for Visual Studio and include njsproj files accordingly. However, you do not need Visual Studio to run these samples. Just ignore the nsjprof files, if you wish, and open the app.js in your choice of editor such as Visual Studio Code, or even a text editor, such as Sublime. The choice is yours!

4. Azure/azure-documentdb-datamigrationtool

This repo contains the DocumentDB Data Migration Tool – an open source solution to import data to DocumentDB from a variety of sources with ease and simplicity. The migration tool supports migration of data from the following sources:

  • Azure Tables
  • JSON files
  • MongoDB
  • SQL Server
  • CSV files
  • RavenDB
  • Amazon DynamoDB
  • HBase
  • DocumentDB collections

While the import tool includes a graphical user interface (dtui.exe), it can also be driven from the command line (dt.exe). In fact, there is an option to output the associated command after setting up an import through the UI. Tabular source data (e.g. SQL Server or CSV files) can be transformed such that hierarchical relationships (sub-documents) can be created during import. Check it out to learn more about data source options, sample command lines to import from each source, target options, and viewing import results.

5. Azure/azure-documentdb-python

This repo contains Python sample solutions showing common operations on Azure DocumentDB. You will learn how to use Azure DocumentDB to store and access data from a Python web application hosted on Azure and presumes that you have some prior experience using Python and Azure websites. Another good tutorial to follow up with is Python Flask Web Application Development with DocumentDB, where you will build a simple voting application that allows you to vote for a poll using Python against DocumentDB.

6. Azure/azure-documentdb-node-q

This repo has DocumentDB Node.js Q promises wrapper. If you don’t know anything about Q promises, read Promises in Javascript With Q. The repo project provides a “Hello world example code using Q promises” that makes it very easy to interact with Azure DocumentDB. You will seriously witness here that DocumentDB is built with a deep commitment to the JSON and JavaScript. This approach of “JavaScript as a modern day T-SQL” frees application developers from the complexities of type system mismatches and object-relational mapping technologies. The samples in this repo will help you get going with the JavaScript SDK to interact with the Azure DocumentDB service.

7. Azure/azure-documentdb-js-server

Before you head to this repo, maybe watch this video first – to get a brief introduction to Azure DocumentDB's server-side programming model. You will learn how DocumentDB’s language integrated, transactional execution of JavaScript lets developers write stored procedures, triggers and user defined functions (UDFs) natively in JavaScript. This allows developers to write application logic which can be shipped and executed directly on the database storage partitions.

8. Azure/azure-documentdb-java

This project provides a client library in Java that makes it easy to interact with Azure DocumentDB. In this repo, you will find a number of Java code samples working with DocumentDB. If you feel comfortable and up to it, you can build the entire Java web application using DocumentDB in just a few steps. For documentation please see the Microsoft Azure Java Developer Center and the JavaDocs.

9. Azure/azure-documentdb-hadoop

This repo provides a client library in Java that allows Microsoft Azure DocumentDB to act as an input source or output sink for Hadoop MapReduce, Hive and Pig jobs. This tutorial shows you how to run Apache Hive, Apache Pig, and Apache Hadoop MR jobs on Azure HDInsight with DocumentDB's Hadoop connector. DocumentDB's Hadoop connector allows DocumentDB to act as both a source and sink for Hive, Pig, and MapReduce jobs. This tutorial uses DocumentDB as both the data source and destination for Hadoop jobs, and shows how to do it. I recommend getting started by watching the following video, where we run through a Hive job using DocumentDB and HDInsight.

Hive, Pig, and MapReduce jobs. This tutorial uses DocumentDB as both the data source and destination for Hadoop jobs, and shows how to do it. I recommend getting started by watching the following video, where we run through a Hive job using DocumentDB and HDInsight.

10. Azure-Samples/documentdb-node-todo-app

Finally, this repo contains the source code for a complete application. The sample shows how to use the Microsoft Azure DocumentDB service to store and access data from a Node.js Express application hosted on Azure Websites.

For a complete end-to-end walk-through of creating this application, please read the full tutorial on the Azure documentation page. The code included in this sample is intended to get you going with a simple Node.js Express application that connects to Azure DocumentDB and showing how to interact with DocumentDB using the documentdb npm package. It is not intended to be a set of best practices on how to build scalable enterprise grade web applications, but it’s a great start.


P.S. If you’ve never even heard the word “NoSQL”, first of all – wow! You are at the end of the blog, and still paying attention. That’s awesome! Second, a quick way to learn about DocumentDB and see it in action is to follow these three steps:

  1. Watch the two minute What is DocumentDB? video, which introduces the benefits of using DocumentDB.
  2. Watch the three minute Create DocumentDB on Azure video, which highlights how to get started with DocumentDB by using the Azure Portal.
  3. Visit the Query Playground, where you can walk through different activities to learn about the rich querying functionality available in DocumentDB. Then, head over to the Sandbox tab and run your own custom SQL queries and experiment with DocumentDB.