Skip to content

Instantly share code, notes, and snippets.

@xjamundx
Created April 11, 2011 13:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xjamundx/913522 to your computer and use it in GitHub Desktop.
Save xjamundx/913522 to your computer and use it in GitHub Desktop.
using my simple mongohq wrapper
// 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