I was looking at the docs, but they just have this stated:
// Deleting collections from a Web client is not recommended.
For reference, I'm moving a document from 1 collection to another and that document has subcollections.
To move it I do the following:
- set the new document (
path
is a path to the new collection to place the doc in) - copy the collections from the old document to the new document
setDoc(doc(db, path), inquiry);
console.log(updatesCollection);
updatesCollection.docs.map((updateDocument) => {
(async () => (addDoc(collection(db, `/closed/${id}/updates`), updateDocument.data())))();
});
- delete the old document
(async () => await deleteDoc(doc(db, "active/" id)))();
this leaves the old path open and the subcollection still there, is there a way I can delete it? this is a full react app so I want to do it client-side.
CodePudding user response:
this leaves the old path open and the subcollection still there
That's indeed the expected behavior since deleting a document doesn't mean that all subcollections that exist within that document will be deleted as well.
As the error message states:
Deleting collections from a Web client is not recommended.
Don't do that. If you want to delete a document along with all the documents within its subcollections, please note that you have to do it manually.