Вот что я сделал:
deleteCollection(db, collectionPath, batchSize) {
let collectionRef = db.collection(collectionPath);
let query = collectionRef.orderBy('__name__').limit(batchSize);
return new Promise((resolve, reject) => {
this.deleteQueryBatch(db, query, batchSize, resolve, reject);
});
}
deleteQueryBatch(db, query, batchSize, resolve, reject) {
query.get()
.then((snapshot) => {
// When there are no documents left, we are done
if (snapshot.size === 0) {
return 0;
}
// Delete documents in a batch
let batch = db.batch();
snapshot.docs.forEach((doc) => {
batch.delete(doc.ref);
});
return batch.commit().then(() => {
return snapshot.size;
});
}).then((numDeleted) => {
if (numDeleted === 0) {
resolve();
return;
}
// Recurse on the next process tick, to avoid
// exploding the stack.
process.nextTick(() => {
this.deleteQueryBatch(db, query, batchSize, resolve, reject);
});
})
.catch(reject);
}
* ИСПОЛЬЗОВАНИЕ 1006 *
flushDB() {
this.deleteCollection(db, 'users', 100)
this.deleteCollection(db, 'featureFlags', 100)
this.deleteCollection(db, 'preferences', 100)
}