0
votes

I am really confused on this. If I programitically delete all the documents from a Firestore collection, the collection itself is also deleted:

this.afs.collection(myCollecton).doc(docId).delete();

But if I delete all the documents using the Firebase console online, I don't always see the collection deleted! I literally deleted all the documents from a collection and it still was in the console. I could immediately create another document in the collection. But sometimes the collection did just go away...?!

I read through some posts like Deleting all documents in Firestore collection but have not seen anything to account for this.

Since a collection must have a document it, I guess it's inferred that deleting all of the documents would delete the collection. The delete-data documentation doesn't mention this, but even so, why do I only sometimes see the collection deleted???

1
Did you try refreshing the console page? If there are no documents in a collection, the view of the collection should disappear when refreshed. Sometimes the console is not able to automatically update itself. - Doug Stevenson
I posted and then saw your comment Doug. If you post as an answer, I'll accept yours but that was it. Still a little confusing, but understandable. Thanks! - Love to Code
Don't worry about it, you got it. - Doug Stevenson
Appreciate that Doug! - Love to Code

1 Answers

1
votes

ARG! I figured out the what and believe I understand the why: Has to do with refreshing the browser. The way the console acts may cause confusion for new Firestore users.

Deleting all documents deletes the collection as well, but it can appear that the collection did not actually get deleted if you don't refresh the browser. I guess the collection is still deleted but if you immediately create a new document, I guess it's the same as calling:

db.collection(myCollecton).doc(docId).set(data)

and the missing collection is created? If you refresh the brwoser right after deleting the last document, then you won't see the collection.

Hopefully this may someone else's confusion if they hit this.