Reputation: 1802
I have few hundreds docs in a collection. And few of them are corrupted and I want to delete them. I know how to find the corrupted documents and I get them as a result of a query. But it's just a data, there is no document ID or anything.
So my question is, how to delete documents which I receive in query? Or is there another way how to delete documents based on some property?
getData(target) {
return this.afs.collection('someCollection', ref => {
let query: firebase.firestore.CollectionReference | firebase.firestore.Query = ref;
query = query.where('label', '==', target);
return query;
});
}
this.dataService.getData('CorruptedLabel').valueChanges().subscribe(resp => {
console.log('resp', resp); // Here I get and array of objects
// I would like to go through that array and call delete() on each item
});
Upvotes: 1
Views: 1279
Reputation: 6900
You can get the firestore document reference and delete the doc
this.dataService.getData('CorruptedLabel').snapshotChanges().subscribe(snapshots
=> {
snapshots.forEach(snapshot => {
if(snapshot){
this.afs.collection('someCollection').doc(snapshot.payload.doc.id).delete();
}
}
});
Upvotes: 1