Skip to content

Instantly share code, notes, and snippets.

@tanepiper
Created July 9, 2012 22:03
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 tanepiper/1ff8a73e118d2b0d521d to your computer and use it in GitHub Desktop.
Save tanepiper/1ff8a73e118d2b0d521d to your computer and use it in GitHub Desktop.
var mongodb = require('mongodb');
var domain = require('domain');
module.exports = function(instance) {
var dbdomain = domain.create();
dbdomain.on('error', function(error) {
instance.logger.error('Domain Error in River DB', error);
dbdomain.dispose();
});
dbdomain.run(function() {
var db = instance.punchbag.mongodb = {};
db.database = new mongodb.Db(
instance.options.punchbag.db.name,
new mongodb.Server(instance.options.punchbag.db.host, instance.options.punchbag.db.port, {}),
{ native_parser: false, auto_reconnect:false }
);
db.close = function() {
db.database.close();
};
db.database.open(function(error) {
if (error) {
throw error;
}
db.database.authenticate('', '', function() {
if (error) {
throw error;
}
instance.logger.info('Punchbag Database Connected and Authorised');
});
});
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment