Home > other >  Flutter Firestore Get Document ID of all empty docs that have subcollections
Flutter Firestore Get Document ID of all empty docs that have subcollections

Time:11-27

I have too many documents in firestore that don't have data in them but they have subcollections. How do I delete them in flutter?

I only want to delete empty documents.

I want to delete all these subcollection that are in italic

CodePudding user response:

Actually you cannot delete these documents without deleting the corresponding sub-collection(s) (i.e. the items subcollection shown in the screenshot included in your question).

See how these "empty documents" are displayed with an italic font in the Firebase console: This is because these documents are only present (in the console) as "container" of one or more sub-collection but they are not "genuine" documents. They simply don't exist in the Firestore database, but they are materialized in the console in order to allow you to navigate to the subcollections.

Therefore you cannot delete them, since they don't exist: the only way to have them disappearing from the console is, again, to delete the corresponding sub-collection(s)... which you probably don't want to do!


Extra note: Your question title is "Flutter Firestore Get Document ID of all empty docs that have subcollections" but from the body of your question it seems that you don't want to get their ID but to delete them. If you do want to get their IDs (because you use a Collection Group query and therefore you don't now the collection parent ID), you would use the parent property of each subcollection.

  • Related