In the previous post you learned how to setup an Express Node.js application in Microsoft Azure and also make it a unit of continuous deployment using Git. An Express Node.js application in silos without a data store to back it is not very useful. In this post you will explore setting up a MongoDB database using the Microsoft Azure marketplace that can then act as a repository for your Express Node.js web application to store large scale unstructured data. Hosted in Azure, it is limited only by the ability of the platform to scale, which is virtually infinite.
The first thing you would need to do is to subscribe to the MongoLab service from the Microsoft Azure store. MongoLab is a fully hosted MongoDB cloud database that is available with all the major cloud providers, including Azure.
To add MongoLab service to your subscription, click New in your management portal, and select the Store (preview) option.
Note that, depending on your subscription, the store may or may not be available to you. Reach out to Azure support if you need more details.
Find MongoLab from under the App Services category in the store and select to add it to your subscription.
500 MB is free to use. Enter your subscription details in the form that is presented and then click Purchase to complete the operation of adding it to your subscription. You can now use the Mongoose Node.js driver to connect to the MongoLab service database and start storing your model data.
To install the Mongoose driver, run the following command in your console:
npm install mongoose –save
You are now all set to connect to the MongoDB database hosted in Azure. Get the connection string for the hosted instance and then use it in your express Node.js application controller code:
var mongoose = require('mongoose');
You can use the
model function to get associate a model with the Mongoose schema and then perform your operations on the model data.
MongoDB, web application, Azure, Node.js