Last active
January 26, 2016 05:26
-
-
Save tgoyer/7ae436eb1933eed7dfd0 to your computer and use it in GitHub Desktop.
Test Database Connection. Pass in flushData == true into init() rebuild test data.
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 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