1

I understand that we can't delete a document which has subcollection. Well we can, but the collection is still accessable which is not good.

In that question, Why "single bulk" delete Collection in Firestore is not possible like it is whit real time Database? ,the logical delete was recommended by renaming the document that has subcollections.

How can we rename a document? I can't find it in the docs.

Thank you

Snake
  • 14,228
  • 27
  • 117
  • 250

1 Answers1

0

You cannot find in the docs because there is no API for doing this. Firestore doesn't have the concept of renaming documents or a part of the path via update operation. Instead, you will have to first get the object, create it again with another name and in the end completely remove the existing old one.

Please take a look at one of my answers, where I have explained how to move a document which is basically the same.

Alex Mamo
  • 130,605
  • 17
  • 163
  • 193
  • Thanks Alex. My goal of renaming is to perform a logical delete on that document according to the post in the question. Although your suggested solution would work by cloning but the root issue of having subcollections existing under the old document still exists,.. Which is why I am renaming in the first place – Snake Mar 06 '18 at 08:29
  • 1
    In this case all you need to do is to use the answer from this [post](https://stackoverflow.com/questions/49125183/how-to-model-this-structure-to-handle-delete/49126223), in which you need to delete the documents in a one by one manner without the need to rename a document. – Alex Mamo Mar 06 '18 at 08:37