[Windows Azure] Just deployed first MongoDB Free Instance in the Cloud

Wednesday, January 18, 2012

 

Just hosted my first MongoDB instance in the cloud and called it from a Node program. It is incredible easy and free, go to:
 
 
It took be about 2 mins to setup. After setup I ran the following local Node program:
 
var mongoose = require('mongoose');
var db = mongoose.connect('mongodb://<user>:<password>@ds029257.mongolab.com:29257/mongo1');
 
Schema = mongoose.Schema;
 
Beer = new Schema({
    brand       : String,
    rating      : Number
});
 
var BeerModel = mongoose.model('Beer', Beer);
 
var first = new BeerModel({  brand:'second',  rating: 41});
 
first.save(function(err){
    if (err) { console.log(err); }
});
 
BeerModel.find({ rating: {$gt: 35} },
    function(err, beers) {
        beers.forEach(function(beer){
            console.log(beer);
        });
    });
 
Note: Now your homework is to make calls to mongolabs hosted MongoDB from an Node/Express application deployed on Heroku. 

_______________________________________________________________________________
Zia Khan: http://www.google.com/profiles/ziakhan
Become my friend on Facebook: http://www.facebook.com/ziakhan
Mobile: 92-300-826-3374 (Pakistan)
Microsoft's Windows Azure Discussion Group: 3,200+ Members
CFA, CPA, and CMA Exam Preparation Discussion Group: 3,900+ Members
_______________________________________________________________________________

__._,_.___
Recent Activity:
Cloud Computing Education: http://www.OperationBadar.net
MARKETPLACE

Stay on top of your group activity without leaving the page you're on - Get the Yahoo! Toolbar now.

.

__,_._,___

0 comments:

Post a Comment