Skip to content
This repository has been archived by the owner on Apr 8, 2019. It is now read-only.

Change deleteAll to use batch-like style #12

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions entity/entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,22 +282,24 @@ export class Entity {

if (collectionName == undefined)
collectionName = this.className()

let collection: AngularFirestoreCollection<any> = fireStore.collection<any>(collectionName);
this.getAll(fireStore, collectionName).subscribe(result => {
let documents = [];
collection.ref.get().then( list =>{

for (let i = 0; i < result.length; i++) {
documents.push(result[i].delete(collectionName));
}
const batch = fireStore.firestore.batch();

list.forEach( doc => {
batch.delete(doc.ref)
})

Promise.all(documents).then(result => {
batch.commit().then(() => {
observer.next();
observer.complete();
});

}, err => {
observer.error(err);
})
},err => {
observer.error(err);
})

});
}
Expand Down