Posted by Anuraj on Monday, April 27, 2015 Reading time :1 minute
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.
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.
Next screen will confirm the purchase and creates the Mongo Database on Azure.
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.
You can get the connection details from Connection Info button, which is required to connect to MongoDB from ASP.NET code.
Now you can use the connection string in C# code. I am using last post code here.
_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.
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 :)