Skip to content

Instantly share code, notes, and snippets.

@stevepm
Forked from qnub/database-reset.js
Last active August 29, 2015 14:19
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 stevepm/da79a328b972e0484dac to your computer and use it in GitHub Desktop.
Save stevepm/da79a328b972e0484dac to your computer and use it in GitHub Desktop.
if (process.env.IS_MIRROR) {
Meteor.methods({
'loadFixtures': function(){
console.log('Loading default fixtures');
// TODO: add your fixtures here
// Example below:
//*****EXAMPLE********
//Accounts.createUser({
// email: 'email@example.com',
// password: '123456'
//});
//*****EXAMPLE********
console.log('Finished loading default fixtures');
},
'clearDB': function(){
console.log('Clear DB');
var collectionsRemoved = 0;
var db = Meteor.users.find()._mongo.db;
db.collections(function (err, collections) {
var appCollections = _.reject(collections, function (col) {
return col.collectionName.indexOf('velocity') === 0 ||
col.collectionName === 'system.indexes';
});
_.each(appCollections, function (appCollection) {
appCollection.remove(function (e) {
if (e) {
console.error('Failed removing collection', e);
fut.return('fail: ' + e);
}
collectionsRemoved++;
console.log('Removed collection');
if (appCollections.length === collectionsRemoved) {
console.log('Finished resetting database');
}
});
});
});
console.log('Finished clearing');
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment