Deploy your MongoDB application on Azure with MongoLab add-on

Posted by Anuraj on Monday, April 27, 2015

.Net .Net 4.0 ASP.Net ASP.Net MVC Web API Windows Azure

MongoLab is MongoDB-as-a-Service (DBaaS) platform. The Azure Marketplace MongoLab add-on will provide you with a MongoDB database hosted in the Azure cloud and managed by MongoLab’s cloud database platform. To deploy your application in Azure with Mongolab, first you need to provision your Database. You can do it from Azure Management portal. (The MongoLab workflow is not yet supported in the Preview Portal). Open the Azure Market Place, under App Services, you can find MongoLab.

MongoLab from Azure Marketplace

In the Next screen you can select the Plan and provide the name of the Database. To evaluate MonogLab comes with a sandbox plan, which is free, for this post I choose the sandbox plan.

MongoLab - Plan and DB name

Next screen will confirm the purchase and creates the Mongo Database on Azure.

MongoLab - Purchase confirmation

Once the Database created, you can manage it using MongoLab management portal, link to the portal available in the Azure Management Portal. You require a connection string to connect to MongoDB from ASP.NET which is also available in the portal.

MongoLab - Database options

You can get the connection details from Connection Info button, which is required to connect to MongoDB from ASP.NET code.

MongoLab - Database Connection Info

Now you can use the connection string in C# code. I am using last post code here.

_mongoClient = new MongoClient("mongodb://MongoSample:ABC00129020.ABC18991ABJ@SHJWHJS.mongolab.com:34348/MongoSample");
_mongoDatabase = _mongoClient.GetDatabase("MongoSample");
_employeeCollection = _mongoDatabase.GetCollection<Employee>("Employees");

_mongoClient.GetDatabase() method, you need to provide the database name you just created with MongoLab. Except this and connection string change, there is no difference in code. You can use kpm publish option to publish the package and can use FTP deploy option to deploy your code to azure.

You can manage your collection and database from MongoLab management portal. Here is the Mongolab Management portal for the MongoDB just created.

MongoLab - Management Portal

You can connect to MongoLab DB from Mongo shell as well. Always get the connection string or any other settings from configuration file instead of hard coding it in the code.

Happy Programming :)


Similar Posts


Did you like this article? Share it with your friends

Facebook Twitter Google+ LinkedIn Reddit StumbleUpon



Subscribe


Copyright © 2017 - Anuraj P. Blog content licensed under the Creative Commons CC BY 2.5 | Unless otherwise stated or granted, code samples licensed under the MIT license. This is a personal blog. The opinions expressed here represent my own and not those of my employer. Hosted with ❤ by GitHub