-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathcleaner.js
46 lines (40 loc) · 1.38 KB
/
cleaner.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
if (Meteor.isServer) {
const _resetDatabase = function (options) {
if (process.env.NODE_ENV !== 'development') {
throw new Error(
'resetDatabase is not allowed outside of a development mode. ' +
'Aborting.'
);
}
options = options || {};
var excludedCollections = ['system.indexes'];
if (options.excludedCollections) {
excludedCollections = excludedCollections.concat(options.excludedCollections);
}
var db = options.db || MongoInternals.defaultRemoteCollectionDriver().mongo.db;
var getCollections = Meteor.wrapAsync(db.collections, db);
var collections = getCollections();
var appCollections = _.reject(collections, function (col) {
return col.collectionName.indexOf('velocity') === 0 ||
excludedCollections.indexOf(col.collectionName) !== -1;
});
_.each(appCollections, function (appCollection) {
var remove = Meteor.wrapAsync(appCollection.remove, appCollection);
remove({}, {});
});
};
Meteor.methods({
'xolvio:cleaner/resetDatabase': function (options) {
_resetDatabase(options);
}
});
resetDatabase = function(options, callback) {
_resetDatabase(options);
if (typeof callback === 'function') { callback(); }
}
}
if (Meteor.isClient) {
resetDatabase = function(options, callback) {
Meteor.call('xolvio:cleaner/resetDatabase', options, callback);
}
}