collection('something').delete() does not recursively delete nested collections #6281
-
there's a function for recursive delete in the official firestore library i do think we should add this to the library |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 10 replies
-
Unfortunately that's not the way this has to work because deleting recursively requires running firestore operations in large batches (because there is a 500 document limit to deletes, and the recursive operation may total more than that...), and it's unreliable in a mobile context. It has to be done in a callable function, which is not something we can directly package for people. But firebase has provided ample documentation and sample code for this case, and I use it myself in my apps. It works great This is what you want
Integrate that to your functions implementation and call it from your app as needed |
Beta Was this translation helpful? Give feedback.
-
deleteCollectionRecursively: (collection: FirebaseFirestoreTypes.CollectionReference<FirebaseFirestoreTypes.DocumentData>) => {
return new Promise<void>(async (resolve, reject) => {
const [err, data] = await to(collection.get());
if (err) reject(err);
if (data?.docs.length)
await Promise.all(data.docs.map(doc => collection.doc(doc.id).delete()));
resolve();
})
} dont worry mate i just found the solution it works quite well |
Beta Was this translation helpful? Give feedback.
-
In the node js environment, you can delete nested documents and collections via import { firestore } from "firebase-admin";
await firestore().recursiveDelete(collectionRef || documentRef); |
Beta Was this translation helpful? Give feedback.
Unfortunately that's not the way this has to work because deleting recursively requires running firestore operations in large batches (because there is a 500 document limit to deletes, and the recursive operation may total more than that...), and it's unreliable in a mobile context. It has to be done in a callable function, which is not something we can directly package for people.
But firebase has provided ample documentation and sample code for this case, and I use it myself in my apps. It works great
This is what you want
Integrate t…