We're happy to announce that MongoLab is now available as an add-on to AppHarbor, the fully-hosted .NET Platform as a Service provider.
Now that MongoLab has docked in AppHarbor we'd like to show you how quickly you can assemble a cloudworthy MongoDB C# web application.
AppHarbor compiles your application directly from a .NET solution file. Putting an application to AppHarbor, therefore, is as simple as pushing your project directory into the source control repository that AppHarbor sets up for your application. We do this with Git.
We're going to go through 3 major phases here. We will:
- Set up our AppHarbor application using just a web browser.
- Obtain, configure, and push a sample application using Git Bash and Visual Web Developer Express.
- Try out the application and peek under the hood into MongoDB.
Prepare the Harbor!
You can prepare AppHarbor and sign up for MongoLab in a very short amount of time, using only your browser.
- Create an account at www.appharbor.com.
- From the Your Applications screen, enter test-app as your application name and click Create New.
- You'll land at your application's control console. Click add-on catalog and locate the MongoLab entry.
- Click See More to visit the MongoLab add-on screen.
- Click Install next to any of the MongoLab plans. If you select a for-pay plan, you'll be required to enter your payment information with AppHarbor.
Your MongoLab database is provisioned automatically. You'll have access to all of the MongoLab web administration tools and services like automatic backups and 24x7 monitoring. When installation succeeds, you'll see a banner atop your Application screen.
- From the sidebar on your Application screen, click Repository URL. This copies your application's Git repository URL to your clipboard. Paste it somewhere useful to save for later.
Prepare Your Ship!
This lightweight C# demo is provided courtesy of AppHarbor's Michael Friis. You can check it out on GitHub here. Before you proceed, make sure you have a C# dev environment ready to go. This demo was completed using Visual Web Developer 2010 Express.
You'll also need to get the code to AppHarbor. AppHarbor also provides instructions for GitHub, CodePlex, and BitBucket; we opted for Git for Windows, using the "use Git Bash only" option. At the Git Bash console:
cd <Your directory>
git clone https://github.com/friism/MvcMongoDbTestApplication.git
The demo has been placed in the MvcMongoDbTestApplication subdirectory. It is at this point you can open the solution in Visual Web Developer and inspect the code. This simple webform guestbook-style app selects and displays the Thingies available in the MongoDB database, and allows you to add more.
In particular, check out Line 20 of BaseController.cs. Here's where Michael's application references the AppHarbor configuration variable MONGOLAB_URI. This is a string containing your database's fully-qualified mongodb:// connection URI, including authentication credentials.
Connecting to MongoDB is as simple as passing this value to MongoDatabase.Create(). For more information, AppHarbor has a great C#/MongoDB primer over at Using MongoDB.
When you're ready, grab that Repository URL we asked you to save in Step #6 and, within Git Bash:
cd <Your directory>/MvcMongoDbTestApplication git add . git commit -m 'all hands prepare to set sail...' git remote add appharbor <Repository URL> git push appharbor master <enter password>
Open your AppHarbor application console again. Your git push has become a build operation. Once the build is complete, click Go to your application and add some new some thingies into the cloud!
You can view the data backing your Thingies application in the MongoLab database admin tool. To do this:
- Click the MongoLab entry in your Installed add-ons list.
- Follow the Go To MongoLab link.
AppHarbor redirects you to the MongoLab admin UI. Your database is now at your fingertips.
- Click the Thingies collection to drill down to the MongoDB document level.
- Click on any of the documents to edit it directly.
We're going to leave you here to experiment with MongoLab's JSON-validating document editor. For other features of the MongoLab user interface, check out List View and Saved Queries. And by all means, if you have any questions, drop us a line at firstname.lastname@example.org.
We're excited to be able to serve the .NET community through AppHarbor and look forward to seeing some great new apps. Remember, the world always needs adventurers!