[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["很难理解","hardToUnderstand","thumb-down"],["信息或示例代码不正确","incorrectInformationOrSampleCode","thumb-down"],["没有我需要的信息/示例","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-08-25。"],[],[],null,["# Bulk delete data\n================\n\nUse the managed bulk delete service to delete data from your database. This\nfeature supports deletion against one or more collection groups.\n\nThis page describes how to delete documents in bulk using\nthe managed bulk delete service. The\nFirestore managed bulk delete service is available through\nthe [`gcloud`](https://cloud.google.com/sdk/gcloud/)\ncommand-line tool and the Firestore [REST API](/firestore/docs/reference/rest/v1/projects.databases/bulkDeleteDocuments).\n| **Caution:** Bulk deleting data from Firestore incurs one delete operation per document deleted and some read operations based on a fraction of total documents read. However, these operations don't appear in the usage section of the console. Make sure that you understand this before issuing bulk deletes to avoid billed charges.\n\nBefore you begin\n----------------\n\nBefore you can use the managed bulk delete service, you must complete the\nfollowing tasks:\n\n1. [Enable\n billing for your Google Cloud project.](https://cloud.google.com/billing/docs/how-to/modify-project) Only Google Cloud projects with billing enabled can use the bulk delete functionality.\n2. Make sure your account has the necessary permissions for\n Firestore. **If you are the project owner,\n your account has the required permissions.** Otherwise, the following\n roles grant the necessary permissions for bulk delete operations:\n\n - [Firestore roles:](https://cloud.google.com/firestore/docs/security/iam#predefined_roles) `Owner`, `Cloud Datastore Owner`, or `Cloud Datastore Bulk Admin` **Note:** These Datastore roles also grant permissions in Firestore.\n\n### Set up `gcloud` for your project\n\nYou can initiate bulk delete operations through the Google Cloud console or\nthe `gcloud` command-line tool. To use `gcloud`, set up the command-line tool\nand connect to your project in one of the following ways:\n\n- Access `gcloud` from the Google Cloud console using [Cloud Shell](https://cloud.google.com/shell/).\n\n [Start Cloud Shell](https://console.cloud.google.com/?cloudshell=true)\n\n Make sure `gcloud` is configured for the correct project: \n\n gcloud config set project [PROJECT_ID]\n\n- [Install and initialize the Google Cloud SDK.](https://cloud.google.com/sdk/docs/quickstarts)\n\nBulk delete data\n----------------\n\nA bulk delete operation first finds all applicable documents in your database and deletes them in batches. You may still query or read these documents while the results may vary based on the progress made. Bulk delete doesn't delete any documents added or modified after the operation starts.\n| **Note:** If you plan to delete all documents in the database, see the [database deletion feature](/firestore/docs/manage-databases#delete-database) instead.\n\n### Bulk delete specific collection groups\n\n### gcloud\n\nTo bulk delete specific collection groups, use the\n[`--collection-ids`](https://cloud.google.com/sdk/gcloud/reference/beta/firestore/bulk-delete#FLAGS) flag. The operation deletes only\nthe collection groups with the given IDs.\n\n\n| **Note:** Bulk deleting a collection won't automatically delete all the child collections. You also need to specify the child collection groups.\n\n\u003cbr /\u003e\n\n```\ngcloud firestore bulk-delete \\\n--collection-ids=[COLLECTION_GROUP_ID_1_OR_KIND_1],[COLLECTION_GROUP_ID_2_OR_KIND_2],[SUBCOLLECTION_GROUP_ID_1_OR_KIND_3] \\\n--database=[DATABASE]\n```\n\nManage bulk delete operations\n-----------------------------\n\nAfter you start a bulk delete operation, Firestore assigns\nthe operation a unique name. You can use the operation name to delete,\ncancel, or check the status of the operation.\n\nOperation names are prefixed with `projects/[PROJECT_ID]/databases/[DATABASE_ID]/operations/`,\nfor example: \n\n```\nprojects/my-project/databases/(default)/operations/ASA1MTAwNDQxNAgadGx1YWZlZAcSeWx0aGdpbi1zYm9qLW5pbWRhEgopEg\n```\n\nHowever, you can leave out the prefix when specifying an operation name for\nthe `describe`, `cancel`, and `delete`commands.\n\n### List all bulk delete operations\n\n### gcloud\n\nUse the [`operations list`](https://cloud.google.com/sdk/gcloud/reference/firestore/operations/list) command to see all running and recently completed operations, including bulk delete operations: \n\n```\ngcloud firestore operations list\n```\n\n### Check operation status\n\n### gcloud\n\nUse the [`operations describe`](https://cloud.google.com/sdk/gcloud/reference/firestore/operations/describe) command to show the status of a bulk delete operation. \n\n```\ngcloud firestore operations describe [OPERATION_NAME]\n```\n\n#### Estimate the completion time\n\nA request for the status of a long-running operation returns the metrics\n`workEstimated` and `workCompleted`. Each of these metrics is returned in both\nnumber of bytes and number of documents:\n\n- `workEstimated` shows the estimated total number of bytes and documents an\n operation will process. Firestore might omit this metric if it\n can't make an estimate.\n\n- `workCompleted` shows the number of bytes and documents deleted so far.\n After the operation completes, the value shows the total number of\n bytes and documents that were actually processed, which might be larger than the\n value of `workEstimated`.\n\nDivide `workCompleted` by `workEstimated` for a rough progress estimate. This\nestimate might be inaccurate, because it depends on delayed statistics\ncollection.\n\n### Cancel an operation\n\n### gcloud\n\nUse the [`operations cancel`](https://cloud.google.com/sdk/gcloud/reference/firestore/operations/cancel) command to stop an operation in progress: \n\n```\ngcloud firestore operations cancel [OPERATION_NAME]\n```\n\nCancelling a running operation doesn't undo the operation. A cancelled bulk delete\noperation doesn't recover the deleted documents.\n\n### Delete an operation\n\nUse the [`gcloud firestore operations delete`](https://cloud.google.com/sdk/gcloud/reference/firestore/operations/delete) command to remove\na completed operation from the list of recent operations. To cancel a running operation, use the earlier cancellation operation. \n\n```\ngcloud firestore operations delete [OPERATION_NAME]\n```\n\nBilling and pricing for bulk delete operations\n----------------------------------------------\n\nYou are required to enable billing for your Google Cloud project before you use\nthe managed bulk delete service.\nBulk delete operations are charged for document reads and deletes at the rates listed in [Firestore pricing](/firestore/docs/pricing). Bulk delete operations incur one index entry read per document found and one delete operation per document deleted. You are charged one read operation for up to 1000 index entries read. For example, for a bulk delete operation that deleted 1500 documents, you will be charged with 2 documents reads and 1500 document deletes.\n\n\u003cbr /\u003e\n\nNote that Firestore charges on the actual work done. If the\noperation is cancelled or failed due to user error, you will be charged with\nprogress made. Firestore won't charge reads or deletes for the\ndocuments that are not eventually deleted, such as documents that\nare modified after the delete operation started. The cost will be attributed on\nthe day of operation completion.\n\nBulk delete operations doesn't trigger your\n[Google Cloud budget](https://cloud.google.com/billing/docs/how-to/budgets) alerts until after completion. Similarly,\nreads and deletes performed during a bulk delete operation are applied to\nyour free tier usage after the operation is complete. Bulk delete\noperations don't affect the usage shown in the usage section of the console.\n\n### View bulk delete costs\n\nBulk delete operations apply the `goog-firestoremanaged:bulkdelete`\nlabel to billed operations. In the [Cloud Billing reports page](https://cloud.google.com/billing/docs/how-to/reports#getting_started),\nyou can use this label to view costs related to bulk delete operations.\n\nBest practices\n--------------\n\n\u003cbr /\u003e\n\n[Avoid skipping over deleted data](/firestore/docs/best-practices#avoid-skipping) which might slow down the queries."]]