Skip to content

Instantly share code, notes, and snippets.

@tgoyer
Last active January 26, 2016 05:26
Show Gist options
  • Save tgoyer/7ae436eb1933eed7dfd0 to your computer and use it in GitHub Desktop.
Save tgoyer/7ae436eb1933eed7dfd0 to your computer and use it in GitHub Desktop.
Test Database Connection. Pass in flushData == true into init() rebuild test data.
var mongoose = require('mongoose'),
config = require('./config');
module.exports = {
init: function(flushData) {
mongoose.connect(config.database.mongoUri, function() {
console.log('MONGODB: Connected.');
});
mongoose.connection.on('open', function() {
console.log('MONGODB: Connection opened.');
if (flushData) {
refreshData();
}
});
}
};
function refreshData() {
console.log('MONGODB: Flushing data.');
mongoose.connection.db.dropDatabase();
var loaders = [];
loaders.push(require('./test.data.accounts'));
loaders.push(require('./test.data.profiles'));
loaders.push(require('./test.data.classes'));
loaders.push(require('./test.data.subjects'));
loaders.forEach(function(data) {
data.load();
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment