Reputation: 69
I am new at flutter with firebase so if this feels like a question which has been answered in the docs or by other questions, I apologize!!
Now I am saving user data in firestore and when a user deletes their account, I want that to be deleted too but the Firestore docs says that the only way to delete a collection us:
To delete an entire collection or subcollection in Cloud Firestore, retrieve all the documents within the collection or subcollection and delete them.
This is not recommended for native devs but I thought of an idea:
So firestore overwrites new data against the old one, so if we set a new collection (user-root) which has a single doc with no fields and then delete it, it would be read/write effective as it just overwrites all of the preexisting data.
I have not tried this idea out but if anyone has a better approach to delete collections in firestore, please write an answer!
Reference Links:
Upvotes: 1
Views: 2857
Reputation: 317342
It's not possible to "set a new collection". You can only read, write, and query individual documents within a collection.
The advice you quoted here about deleting a collection is absolutely true - you must query, iterate, and delete each document individually. There are no workarounds for this for web and mobile clients.
If you wish to add a backend to your app, you could use the firebase-tools library in a callable Cloud Function to make this process easier, but that library still follows this process to delete all documents in a collection.
Upvotes: 4