I have an angled application with angularfire. I created this way to delete the collection:
deleteCollection(path: string, batchSize: number): Observable<any> {
const source = this.deleteBatch(path, batchSize);
return source.pipe(
expand(val => this.deleteBatch(path, batchSize)),
takeWhile(val => val > 0)
);
}
/**
* Em teste!
* Apaga toda uma coleção.
*/
private deleteBatch(path: string, batchSize: number): Observable<any> {
const colRef = this.afs.collection(path, ref =>
ref.orderBy('__name__').limit(batchSize)
);
return colRef.snapshotChanges().pipe(
take(1),
mergeMap((snapshot: any) => {
const batch = this.afs.firestore.batch();
snapshot.forEach(doc => {
batch.delete(doc.payload.doc.ref);
});
return fromPromise(batch.commit()).pipe(map(() => snapshot.length));
})
);
}