Skip to content
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 recursiveDelete() to Firestore #649

Merged
merged 2 commits into from May 25, 2021
Merged

feat: add recursiveDelete() to Firestore #649

merged 2 commits into from May 25, 2021

Conversation

thebrianchen
Copy link

@thebrianchen thebrianchen commented May 25, 2021

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.

Note that this is still a BetaApi and may change in the future.

Example:

// Recursively delete a document reference and log the references of failures.
BulkWriter bulkWriter = firestore.bulkWriter();
bulkWriter.addWriteErrorListener(
  (BulkWriterException error) -> {
      if (error.getFailedAttempts() < MAX_RETRY_ATTEMPTS) {
        return true;
      } else {
        System.out.println("Failed write at document: " + error.getDocumentReference());
        return false;
      }
    }
  );
firestore.recursiveDelete(documentReference, bulkWriter);

@thebrianchen thebrianchen requested a review from a team as a code owner May 25, 2021 15:16
@thebrianchen thebrianchen requested a review from a team May 25, 2021 15:16
@thebrianchen thebrianchen requested a review from a team as a code owner May 25, 2021 15:16
@product-auto-label product-auto-label bot added the api: firestore Issues related to the googleapis/java-firestore API. label May 25, 2021
@google-cla google-cla bot added the cla: yes This human has signed the Contributor License Agreement. label May 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: firestore Issues related to the googleapis/java-firestore API. cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants