Created
November 9, 2012 15:55
-
-
Save klclee/4046465 to your computer and use it in GitHub Desktop.
mongodb polling in for express.js
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
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