我收藏了几百份文档。而且他们中很少有人被破坏了,我想把他们删除。我知道如何查找损坏的文档,并通过查询获得它们。但这只是一个数据,没有文档ID或任何东西。
那么,我的问题是,如何删除我在查询中收到的文档?,还是有其他方法可以根据某些属性删除文档?
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
});发布于 2018-01-29 10:09:29
您可以获取消防局文档引用并删除文档。
this.dataService.getData('CorruptedLabel').snapshotChanges().subscribe(snapshots
=> {
snapshots.forEach(snapshot => {
if(snapshot){
this.afs.collection('someCollection').doc(snapshot.payload.doc.id).delete();
}
}
});https://stackoverflow.com/questions/48491684
复制相似问题