Skip to content

Instantly share code, notes, and snippets.

@tjanczuk
Created February 14, 2012 22:18
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 tjanczuk/1831012 to your computer and use it in GitHub Desktop.
Save tjanczuk/1831012 to your computer and use it in GitHub Desktop.
MongoDB
var query = require('url').parse(req.url, true).query
var mongoUrl = query['db'] || 'mongodb://arr:arr@staff.mongohq.com:10024/arr'
var filter = query['host'] ? { hosts: query['host'] } : {}
require('mongodb').connect(mongoUrl, function (err, db) {
if (notError(err))
db.collection('apps', function (err, apps) {
if (notError(err))
apps.find(filter).toArray(function (err, docs) {
if (notError(err)) {
res.writeHead(200)
res.end(JSON.stringify(docs))
}
})
})
})
function notError(err) {
if (err) {
res.writeHead(500)
res.end(err)
}
return !err
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment