forked from Automattic/mongoose
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.js
31 lines (26 loc) · 793 Bytes
/
util.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
'use strict';
exports.clearTestData = function clearTestData(db) {
if (db.models == null) {
return;
}
const arr = [];
for (const model of Object.keys(db.models)) {
const Model = db.models[model];
if (Model.baseModelName != null) {
// Skip discriminators
continue;
}
arr.push(db.models[model].deleteMany({}));
arr.push(db.models[model].collection.dropIndexes().catch(() => {}));
}
return Promise.all(arr);
};
exports.stopRemainingOps = function stopRemainingOps(db) {
// Make all future operations on currently defined models hang
// forever. Since the collection gets deleted, should get
// garbage collected.
for (const name of Object.keys(db.models)) {
const model = db.models[name];
model.collection.buffer = true;
}
};