Created
April 11, 2011 13:38
-
-
Save xjamundx/913522 to your computer and use it in GitHub Desktop.
using my simple mongohq wrapper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// initialize it with your db name and credentials | |
var db = require("./db").init({ | |
user: "username", | |
pass: "password", | |
name: "database", | |
host: "yourmongohqhost.mongohq.com", | |
port: 27094 | |
}); | |
// define your collections | |
db.collection("logs"); | |
db.collection("reviews"); | |
// use basic mongo syntax | |
// for example with ExpressJS | |
app.all('*', function(req, res, next) { | |
db.logs.findOne(function(err, logs) { | |
if (err) return console.log("Error: ", err); | |
res.local('count', logs.count); | |
next(); | |
}); | |
}); | |
app.get('/', function(req, res) { | |
db.logs.update({}, {$inc:{count:1}}); | |
db.reviews.find(function(err, cursor) { | |
cursor.toArray(function(err, reviews) { | |
res.render('home.html', { | |
reviews: reviews | |
}); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment