Reputation: 3016
I have the following database structure:
Firestore-root
|
--- users (collection)
| |
| --- userId (document)
| |
| --- //user details
|
--- products (collection)
|
--- listId (document)
|
--- listProducts (collection)
|
--- productId
|
--- //product details
And I use the following code to delete the documents:
rootRef.collection("users").document(userId).delete(); //works fine
rootRef.collection("products").document(listId).delete();
The first line of code works perfectly but the second is not deleting the list
document. Is it because it has a subcollection beneath it or am I doing something wrong?
How to delete the entire listId
document together with everything it has beneath it?
Thanks!
Upvotes: 2
Views: 2315
Reputation: 599601
Collections that are nested under a document, are not automatically deleted when you delete that document. When you only delete the document itself, the Firebase console will show the document ID in italic. The document itself isn't there anymore (you can see this when you select it, as it won't have any fields), but the nested collections are still accessible.
So I suspect that the products
document is gone, but the nested collections still exist. As the Firestore documentation on deleting collection describes, you'll need to delete the documents from the collection to get rid of it.
Upvotes: 3