The Sheep-Pen of the Shaun

News

Shaun, the author of this blog is a semi-geek, clumsy developer, passionate speaker and incapable architect with about 10 years’ experience in .NET and JavaScript. He hopes to prove that software development is art rather than manufacturing. He's into cloud computing platform and technologies (Windows Azure, Amazon and Aliyun) and right now, Shaun is being attracted by JavaScript (Angular.js and Node.js) and he likes it.

Shaun is working at Worktile Inc. as the chief architect for overall design and develop worktile, a web-based collaboration and task management tool, and lesschat, a real-time communication aggregation tool.

.NET

DocumentDB, provided by Microsoft Azure, is a low latency, NoSQL document database service for web high-scale gaming, social, and Internet of Things (IoT) app scenarios. Similar as Microsoft Azure Table Storage Service, when using DocumentDB developers don’t have to worry about managing schemas anymore. But additionally, DocumentDB automatically indexes all JSON documents added to the database, letting you use familiar SQL syntax to query them without having to specify the schema or secondary indices up front.

At the end of March, Microsoft just announced DocumentDB supports MongoDB protocol in preview. This means we can use existing drivers and tools for MongoDB, leveraging existing MongoDB skills for building application against DocumentDB.

Create DocumentDB with MongoDB Protocol

To enable this preview feature, following this blog post to send request. Several days later there will be an email said it's approved.

After that we can create a DocumentDB service with MongoDB Protocol. Login to azure portal and clicked "New" from the left top side, go to "Data + Storage" and search "DocumentDB" we will find "DocumentDB - Protocol Support for MongoDB".

Select this service and click "Create".

Next, specify the name and resource group of this service.

After clicked "Create" it will be creating. This action may take several minutes.

Access DocumentDB through Existing MongoDB Tool

When DocumentDB was firstly released there's no management tool. This is the reason I created a web-based DocumentDB management tool called "My DocumentDB" here and here. But now this DocumentDB service supports MongoDB protocol, we can use client tools for MongoDB to manage DocumentDB. For example, 3T MongoChef, which are are using right now for MongoDB.

First we need to open the DocumentDB service in azure portal, click "All Settings" and select "Connection String", copy the full connection string.

Next, open MongoChef and click "Connection" on the toolbar, then click "New Connection". In the popup window click "From URI" and paste the connection string we have just copied from the portal.

We can click "Test Connection" to verify if it works.

Now we can view and manage our DocumentDB through 3T MongoChef. For example, I created a database with several collections via azure portal.

In 3T MongoChef, click "Refresh All" in left side context menu it load them.

Double click on one of the collection will list all documents, for example "teams" collection. We can also create a document in 3T MongoChef.

And it will be saved on DocumentDB.

Develop with DocumentDB via Existing MongoDB Driver

There are many MongoDB drivers for many program languages. Currently we are using Mongoose in out Node.js backend service and it's easy as well to use Mongoose to connect our DocumentDB.

Then set the connection string to a variant for future use. Note that the connection string we copied from azure portal does NOT contain database name, which means it will connect to the authentication database "admin". So we need to insert the database in connection string, normally before "?ssl=true" part.

But when I tried map-reduce, it raised an error back to me. Seems that currently DocumentDB does NOT support MongoDB Map-Reduce command. I had sent an email to DocumentDB team and is waiting for their response.

Summary

Why I'm interested in this feature? Well, currently we are using MongoDB which is hosted in several virtual machines and managed by ourselves. But last month we found some database performance issues. As a startup company we don't have enough budget to build a MongoDB expert team. So we have to investigate and tried by ourselves.

After this issue was resolved we found it's necessary to use a self-managed, easy-to-scale NoSQL database service rather than self-host. MongoLab is one of candidate, DocumentDB is the other.

DocumentDB with MongoDB Protocol helps us to migrate our application with very few lines of code changes. Hence if have the same request as our team, you'd better try it as well.

Comments

#re: Play Azure DocumentDB with MongoDB ProtocolPosted by Joe
on 4/15/2016 7:58 AM
I don't get this feature to be honest. It doesn't have feature parity with Mongo. So you say today you want to move your Mongo apps over to this, well that's great as long as your apps only use very basic CRUD. If you do anything like aggregation pipeline, use large docs, use geospatial etc. you're stuck, it just won't work on DocumentDB.

So basically this will be ok if you want to build a new system against DocumentDB using a driver you're familiar with instead of learning a new driver. But that's about it.

Until they get feature parity with Mongo, the notion of app migration is a dream.

I agree with you. Currently there are some Mongo features which DocumentDB doesn't support yet, for example the Map-Reduce. We didn't use other features such as geospatial, GridFS, etc. so we are waiting and to see when Map-Reduce could be ready.

We just in pre-POC phase. DocumentDB is one of our choice. So we are not decided yet to begin move our Mongo app to DocDB, plus this feature is still in Preview. So I personally don't recommend you to use this feature in production.