0

I have a portfolio collection in Firestore. Each portfolio has rents and I can remove any of this. Removing the rent just removes that, the rent itself but when I remove a portfolio that contains rents, it leaves the rents inside of an undefined portfolio.

Here you can see a working one but on the left column (...lzw6I... and others) there are portfolios that were removed and still containing rents:

enter image description here

To remove the portfolio I do something like this:

await FirebaseFirestore.instance
        .collection('users')
        .doc(authService.getUser().uid)
        .collection('portfolios')
        .doc(currentPortfolio['documentID'])
        .delete();

Can I remove the whole document including those collections?

I use Flutter but this shouldn't be a problem.

Dani
  • 3,128
  • 2
  • 43
  • 91
  • I think this may help you! https://firebase.google.com/docs/firestore/manage-data/delete-data#delete_documents https://firebase.google.com/docs/firestore/manage-data/delete-data#collections – Shri Hari L Oct 21 '20 at 13:29
  • 1
    Hey @ShriHari, your comment seems to be a potential answer. – Renaud Tarnec Oct 21 '20 at 13:42
  • Glad that suits! :) – Shri Hari L Oct 21 '20 at 13:46
  • I mean, you should write an answer based on the links you shared, in such a way Dani accepts it. Just copy paste the key points from the documentation that answer to Dani's question. I.e. the subcollection(s) is(are) not deleted automatically. There are some ways to delete them but not with the JS SDK: you may use a Cloud Function for example. – Renaud Tarnec Oct 21 '20 at 14:02
  • following that info I need to get the document collection and remove the documents inside of that collection one by one to "avoid memory issues". There is no other way to do this without getting again all the documents? For a free account this can be a problem incrementing the numbers of readings and updates for a single query – Dani Oct 21 '20 at 14:51
  • There is no client API to do this all at once. You would have to write code to find each document to delete, then delete them all individually. If you want a single "command" to do it all at once, there is a backend tool to do this, which is discussed in the duplicate. – Doug Stevenson Oct 21 '20 at 16:05
  • It's not really optimised considering that they count the updates to the database individually to charge you :/ – Dani Oct 21 '20 at 18:42

0 Answers0