-
Notifications
You must be signed in to change notification settings - Fork 145
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add recursive delete to Firestore class #1494
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1494 +/- ##
==========================================
+ Coverage 98.22% 98.52% +0.29%
==========================================
Files 32 33 +1
Lines 20052 20382 +330
Branches 1390 1328 -62
==========================================
+ Hits 19697 20082 +385
+ Misses 351 295 -56
- Partials 4 5 +1
Continue to review full report at Codecov.
|
@thebrianchen how exactly does this work? What is docRef referring to? How would you delete an entire collection? |
You pass a DocumentReference which will delete the reference, plus any nested collections and documents whose path starts with that of the DocumentReference. You can also pass a CollectionReference, which will delete all directly nested documents and their collections and documents. |
will this work with collections that have queries? const bulkWriter = firestore.bulkWriter();
bulkWriter.onWriteError(() => true);
await firestore.recursiveDelete(firestore.collection('Things').where('UserId', '==', id), bulkWriter); |
No, unfortunately it won't. The underlying implementation issues a "key only query" to recursively list all documents in the collection. This query is limited and does not support any additional constraints. |
Fixes #746.
This PR adds recursive delete functionality to the top level
Firestore
class in a method that recursively deletes all documents and subcollections at and under the specified level. If any delete fails, the promise is rejected with an error message containing the number of failed deletes and the stack trace of the last failed delete. The provided reference is deleted regardless of whether all deletes succeeded.Example: