It’s Time to Switch from MongoDB to Microsoft Azure

clip_image002

Jingya Wang is a Microsoft Student Partner at Imperial College London, the following is a guest blog from Jingya on why to switch from MongoDB to Azure and its No SQL Services for your student projects.

twitter handle - https://twitter.com/JWT0T

GitHub link - https://github.com/JWT0T

Introduction

You are deciding on which database you should use for your web app, searching for NoSQL database and coming cross MongoDB. ‘MongoDB has been #1 in the NoSQL category’! She is the one! Oh, wait a sec, what are the other options? Firebase, CouchDB, DocumentDB… If you are not only looking for a NoSQL database, but also prefer to manage your web app project in one place, Microsoft Azure can be the one!

Microsoft Azure is a cloud computing platform offering 66 products/services. To get started with Azure and its NoSQL services, jump to Get Started with Azure section. If you need to be convinced that Azure is the one, the following section 3 Reasons to Use Azure in Your Web App will tell you

1. why you may favour Azure NoSQL services such as DocumentDB over MongoDB;

2. why you should explore more products on Azure to get most out of it for your web app.

For those who are familiar with MongoDB, the section Switch from MongoDB to Azure NoSQL Services will show you that it is easy to pick up Azure NoSQL databases with your existing MongoDB knowledge. I will focus on a comparison of implementations between Azure DocumentDB and MongoDB, and show you how to think about data in DocumentDB. Hopefully by the end of this section, you will agree with me that DocumentDB is easy to learn, and worth learning.

 

3 Reasons to Use Azure in Your Web App

image

1. Cloud Computing Means Anyone, Anywhere

One of the greatest advantages of using Azure, the cloud computing platform is, all team members can access it from anywhere. For example, DocumentDB is Paas (Platform-as-a-service) by design whereas MongoDB is not. Which means if all data for the web app is stored in DocumentDB, this environment is ideal for both testing, as all team members can work with the same database, rather than creating their own test cases and dummy data using MongoDB and run it in a localhost environment.

Although MongoDB launched its own hosted MongoDB as a service named MongoDB Atlas this year, one thing may put you off immediately - after signing up with your email, it asks immediately for payment. Whereas Azure offers you a 30-days free trial before charging for these services.

2. Host Your Own Web App Easily

No matter you are writing this web app for your university degree, for your work, or even just for fun, you do not want this piece of code to get wasted. Sooner or later, you will start searching for host provider. Azure can be your long-term solution for web hosting.

2.1. Protocol Support for MongoDB

When I was exploring all these products Azure offers, it makes me feel like you can always get something out of it. What if you already have an existing MongoDB app, and it is too late to start with DocumentDB? DocumentDB provides protocol support for MongoDB. For a step-by-step guide, follow the link here.

‘Using this preview functionality, customers can easily build and run applications in the Azure cloud - leveraging DocumentDB’s fully managed and scalable NoSQL databases - while continuing to use familiar skills and tools for MongoDB.’

2.2. Azure App Service

If you hate to start from scratch and prefer your project in an organised manner, Azure App Service can create your web app in three steps. It not only provides you with a HTTPS URL to host your web app, but also provide you with a well-structured project directory with some basic code for you to get started with. The following steps give you with a general idea how to develop your first web app to Azure, and for more information, follow the link here.

image

Here I have selected 1. Web App => 2. ExpressJs. And the following image is the screenshot from ‘Edit your code online’ page. Everything is setup and it is time to start coding!

image

3. There is Something More for Your Web App

For team development, get started for free with Visual Studio Team Services here. Along with DocumentDB and Azure App Service, these services should setup an efficient platform for your web app development.

For maintenance and further improvement, it is critical to analyse logs. you may be also interested in exploring Log Analytics (more information here), combined with Stream Analytics (more information here) for real-time data stream processing, and/or Machine Learning (more information here) for cloud predictive analytics.

Switch from MongoDB to Azure NoSQL Services

Microsoft Azure provides NoSQL services such as

· Azure DocumentDB

· Azure Table Storage

· Azure HBase as a part of HDInsight

· Azure Redis Cache

Among these NoSQL services, DocumentDB is the closest to MongoDB as both are document databases and store JSON(JavaScript Object Notation) or BSON (Binary JSON). If you are familiar with MongoDB, then it is easy to pick up DocumentDB. The following table provides a short summary on implementations between Azure DocumentDB and MongoDB using Node.js.

 

image

 

Due to the nature that both databases are document-oriented, some aspects such as CRUD operations are handled in a similar way. You may need to spend some time thinking about how to model your data in DocumentDB if you are used to MongoDB schema. The article ‘Modelling data in DocumentDB’ here may sharp your way of thinking data in DocumentDB.

There are posts providing a nice comparison between DocumentDB and MongoDB in terms of

- Scaling – Sharding and Replication

- Native REST interface

- Data Interchange Format

- Consistency

- Monitoring

For further reading, I would highly recommend

David Green. ‘MongoDB vs. Azure DocumentDB’ . April 2015.

https://www.simple-talk.com/cloud/cloud-data/mongodb-vs-azure-documentdb/

where he provides a detailed comparison in terms of all aspects I mentioned above.

To learn more with other Azure NoSQL technologies, the document by David Chappell. ‘Understanding NoSQL on Microsoft Azure’. 2014. is a must.

Download PDF https://go.microsoft.com/fwlink/p/?LinkId=330292

Get Started with Azure

1. Create your Azure account

Step 1: To create your Azure account, follow the link here. Click Start for free for 30 days free trial.

image

Step 2: It will lead you to the sign up page as seen below. Notice here it will ask you for Identity Verification by Phone and Identity Verification by Card. Your credit card will not be charged for this offer unless you explicitly remove the spending limit. For more information regarding the free account, see FAQ here.

image

Note: If you are an university student, you can follow the link here to Create a Microsoft Image profile first. After getting verified as a student, follow the link here to Get Microsoft Image with Azure. This benefit should provide you access to the following services (more information here):

- Azure App Services

- SQL Database

- MySQL Database from ClearDB

- Visual Studio Application Insights

- Visual Studio Team Services

But please be aware that you will probably run into the issue as seen below in most cases. Bad! So I would recommend providing your credit card information in exchange of services with full features.

image

2. Azure Portal

Follow the link here to sign in to Azure Portal and start your Azure journey. Azure Portal is the console where you can manage all your Azure products/services. Following is the dashboard displayed when you sign in to the portal.

image

3. Create Azure DocumentDB NoSQL Account and Document Explorer

Follow the link here to create your Azure DocumentDB NoSQL account. Then still in Azure portal, you can launch Document Explorer by following the link here to view JSON objects created using DocumentDB.

4. Create Azure Storage Account and Microsoft Azure Storage Explorer

Follow the link here to create your Azure storage account to get started with Table storage. This account also allows you to work with other storages such as Blob storage. Later you will need Account Name and Access Keys to create connections in your Web App server and view data in Microsoft Azure Storage Explorer.

To view all data in for example, Table Storage, download Microsoft Azure Storage Explorer here. After opening the explorer, to connect to Azure Storage, follow the steps below. This step-by-step guide applies to other Azure Storage services such as Blob Storage.

Step 1:

image

Step 2: Enter Access Key obtained after creating the Storage account on Azure portal, then click Next.

Step 3: Select Use an account name and key to connect to an Azure Storage account and click Next.

Step 4: Enter the storage account name and click Connect.

Step 5: You should be able to find your storage account under Storage Accounts.

Conclusion

To summarise with, Microsoft Azure is perfect to manage your web app project in one place. It provides lots of services such as App Service, Visual Studio Team Services, DocumentDB, Stream Analytics and so on, and each helps with your web app at different stages – setup, development, testing, maintenance and further improvement respectively.

MongoDB is great as a NoSQL database with its strong consistency, flexibility, scalability and performance, but for an organised web app project, Microsoft Azure can be a better solution. Pricing may be the biggest turnoff, but you get 30 days to make up your mind. In the meantime,

image