-
-
Save tanepiper/1ff8a73e118d2b0d521d to your computer and use it in GitHub Desktop.
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 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