Skip to content

Instantly share code, notes, and snippets.

@klclee
Created November 9, 2012 15:55
Show Gist options
  • Save klclee/4046465 to your computer and use it in GitHub Desktop.
Save klclee/4046465 to your computer and use it in GitHub Desktop.
mongodb polling in for express.js
var mongodb = require('mongodb');
var database;
module.exports = {
init: function(host, ip, db_name){
if (database == undefined){
var serverOptions = {
'auto_reconnect': true,
'poolSize': 5
};
var serv = new mongodb.Server('localhost', 27017, serverOptions);
database = new mongodb.Db(db_name, serv, {safe:false});
console.log('starting db with: ', serverOptions);
database.open(function(){});
}
},
db: function(){
return database;
},
close: function(){
database.close();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment