I have an app which uses Firebase's Firestore for persistence. I am using Material's Snackbar for notifications. I have in my service..
deleteProvider(data) {
return this.db.collection(data.table).doc('xzc').delete();
}
Where the data param is simply an object containing the table which I want to perform the action on and the id of the document I wish to delete.
data: { table: 'providers', id: 'some firebase identifier'}
And in my component
onDeleteEntry(event) {
if (event.table === 'providers') {
this.providerService.deleteProvider(event)
.then(() => {
this.snackBar.open('Provider deleted');
})
.catch((error) => {
this.snackBar.open('Error deleting provider', error);
});
}
}
This deletes the document perfectly, but on testing the failed case, it returns true.
For example, if I hard-code 'xyz' into the .doc('xyz') method. The response calls my next() method, rather than my my catch().
deleteProvider(data) {
return this.db.collection(data.table).doc('xyz').delete();
} // returns true on a non-existent document
The Firebase docs emphasise the fact that nested collections will remain after deletion but other than that, the basic functionality of deleting a document is simple and doesn't give very much information other than
db.collection("cities").doc("DC").delete().then(function() {
console.log("Document successfully deleted!");
}).catch(function(error) {
console.error("Error removing document: ", error);
});
What am I missing?
TIA