Firebase Firestore returning true on failed document delete
up vote
0
down vote
favorite
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
angular typescript firebase google-cloud-firestore
add a comment |
up vote
0
down vote
favorite
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
angular typescript firebase google-cloud-firestore
It might be the case that delete() always resolves successfully, regardless if the document previously existed. In that case, it would just be telling you that you can be sure that the document currently doesn't exist, not that it previously existed and now does not. If you want to know that it previously existed, try a transaction that fetches the document first, checks for existence, then deletes it.
– Doug Stevenson
Nov 11 at 17:42
Thanks for your response, Doug. That makes sense. It would be nice to test the failed-case though and I would have thought that deleting a non-existent document would have done it. I'll #askfirebase for clarification.
– Mark Bell
Nov 11 at 17:59
Don't try to force your definition of "failure" on the API. A true failure would be the case where a document does exist, and you ask for it to be deleted, but that didn't happen. Again, try a transaction to ensure that you're only deleting a document that previously exists, if that knowledge is important to you.
– Doug Stevenson
Nov 11 at 18:02
Noted. Cheers, Doug
– Mark Bell
Nov 11 at 19:12
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
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
angular typescript firebase google-cloud-firestore
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
angular typescript firebase google-cloud-firestore
angular typescript firebase google-cloud-firestore
asked Nov 11 at 17:08
Mark Bell
757
757
It might be the case that delete() always resolves successfully, regardless if the document previously existed. In that case, it would just be telling you that you can be sure that the document currently doesn't exist, not that it previously existed and now does not. If you want to know that it previously existed, try a transaction that fetches the document first, checks for existence, then deletes it.
– Doug Stevenson
Nov 11 at 17:42
Thanks for your response, Doug. That makes sense. It would be nice to test the failed-case though and I would have thought that deleting a non-existent document would have done it. I'll #askfirebase for clarification.
– Mark Bell
Nov 11 at 17:59
Don't try to force your definition of "failure" on the API. A true failure would be the case where a document does exist, and you ask for it to be deleted, but that didn't happen. Again, try a transaction to ensure that you're only deleting a document that previously exists, if that knowledge is important to you.
– Doug Stevenson
Nov 11 at 18:02
Noted. Cheers, Doug
– Mark Bell
Nov 11 at 19:12
add a comment |
It might be the case that delete() always resolves successfully, regardless if the document previously existed. In that case, it would just be telling you that you can be sure that the document currently doesn't exist, not that it previously existed and now does not. If you want to know that it previously existed, try a transaction that fetches the document first, checks for existence, then deletes it.
– Doug Stevenson
Nov 11 at 17:42
Thanks for your response, Doug. That makes sense. It would be nice to test the failed-case though and I would have thought that deleting a non-existent document would have done it. I'll #askfirebase for clarification.
– Mark Bell
Nov 11 at 17:59
Don't try to force your definition of "failure" on the API. A true failure would be the case where a document does exist, and you ask for it to be deleted, but that didn't happen. Again, try a transaction to ensure that you're only deleting a document that previously exists, if that knowledge is important to you.
– Doug Stevenson
Nov 11 at 18:02
Noted. Cheers, Doug
– Mark Bell
Nov 11 at 19:12
It might be the case that delete() always resolves successfully, regardless if the document previously existed. In that case, it would just be telling you that you can be sure that the document currently doesn't exist, not that it previously existed and now does not. If you want to know that it previously existed, try a transaction that fetches the document first, checks for existence, then deletes it.
– Doug Stevenson
Nov 11 at 17:42
It might be the case that delete() always resolves successfully, regardless if the document previously existed. In that case, it would just be telling you that you can be sure that the document currently doesn't exist, not that it previously existed and now does not. If you want to know that it previously existed, try a transaction that fetches the document first, checks for existence, then deletes it.
– Doug Stevenson
Nov 11 at 17:42
Thanks for your response, Doug. That makes sense. It would be nice to test the failed-case though and I would have thought that deleting a non-existent document would have done it. I'll #askfirebase for clarification.
– Mark Bell
Nov 11 at 17:59
Thanks for your response, Doug. That makes sense. It would be nice to test the failed-case though and I would have thought that deleting a non-existent document would have done it. I'll #askfirebase for clarification.
– Mark Bell
Nov 11 at 17:59
Don't try to force your definition of "failure" on the API. A true failure would be the case where a document does exist, and you ask for it to be deleted, but that didn't happen. Again, try a transaction to ensure that you're only deleting a document that previously exists, if that knowledge is important to you.
– Doug Stevenson
Nov 11 at 18:02
Don't try to force your definition of "failure" on the API. A true failure would be the case where a document does exist, and you ask for it to be deleted, but that didn't happen. Again, try a transaction to ensure that you're only deleting a document that previously exists, if that knowledge is important to you.
– Doug Stevenson
Nov 11 at 18:02
Noted. Cheers, Doug
– Mark Bell
Nov 11 at 19:12
Noted. Cheers, Doug
– Mark Bell
Nov 11 at 19:12
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53251138%2ffirebase-firestore-returning-true-on-failed-document-delete%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
It might be the case that delete() always resolves successfully, regardless if the document previously existed. In that case, it would just be telling you that you can be sure that the document currently doesn't exist, not that it previously existed and now does not. If you want to know that it previously existed, try a transaction that fetches the document first, checks for existence, then deletes it.
– Doug Stevenson
Nov 11 at 17:42
Thanks for your response, Doug. That makes sense. It would be nice to test the failed-case though and I would have thought that deleting a non-existent document would have done it. I'll #askfirebase for clarification.
– Mark Bell
Nov 11 at 17:59
Don't try to force your definition of "failure" on the API. A true failure would be the case where a document does exist, and you ask for it to be deleted, but that didn't happen. Again, try a transaction to ensure that you're only deleting a document that previously exists, if that knowledge is important to you.
– Doug Stevenson
Nov 11 at 18:02
Noted. Cheers, Doug
– Mark Bell
Nov 11 at 19:12