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










share|improve this question





















  • 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














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










share|improve this question





















  • 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












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










share|improve this question













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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










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
















  • 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

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















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






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































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.




draft saved


draft discarded














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





















































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







這個網誌中的熱門文章

Barbados

How to read a connectionString WITH PROVIDER in .NET Core?

Node.js Script on GitHub Pages or Amazon S3