Skip to content

Instantly share code, notes, and snippets.

@yawnt
Created October 1, 2012 14:53
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 yawnt/3812266 to your computer and use it in GitHub Desktop.
Save yawnt/3812266 to your computer and use it in GitHub Desktop.
var http = require('http'),
mongodb = require('mongodb');
var db = new mongodb.Db('*********************', new mongodb.Server('alex.mongohq.com', 10086, {}));
var inc = 0;
db.open(function (err, db_p) {
if (err) { throw err; }
db.authenticate('nodejitsu', '********************', function (err, replies) {
db.collection('test', function(e, c) {
function handle(req, res) {
var value = inc++;
c.update({ a: inc -1}, {$set: { a: value }}, function() {
res.end(value.toString());
});
}
c.insert({a: inc}, function(e) {
http.createServer(handle).listen(8000);
});
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment