[[["易于理解","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-09-05。"],[[["\u003cp\u003eThe Datastore mode managed bulk delete service allows for the deletion of data from a database, supporting deletion against one or more kinds, and can be accessed via the \u003ccode\u003egcloud\u003c/code\u003e command-line tool or the Datastore mode API.\u003c/p\u003e\n"],["\u003cp\u003eBefore using the bulk delete service, billing must be enabled for the Google Cloud project, or for Firebase projects it must be on the Blaze plan, and users need the correct Datastore mode permissions.\u003c/p\u003e\n"],["\u003cp\u003eBulk delete operations are charged for entity reads and deletes, with one delete operation per entity deleted and one read operation for up to 1000 index entries read, and these charges are not reflected in the console's usage section.\u003c/p\u003e\n"],["\u003cp\u003eYou can manage bulk delete operations by using operation names to check their status, estimate completion time, cancel them, or remove them from the list of recent operations, but canceling doesn't undo deletions already made.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003egcloud firestore operations\u003c/code\u003e commands are used to manage the bulk delete operations, with commands available to list, describe, cancel, and delete the operations, and to estimate the progress of an operation.\u003c/p\u003e\n"]]],[],null,["# Delete entities in bulk\n\nUse the managed bulk delete service to delete data from your database. This\nfeature supports deletion against one or more kinds.\n\nThis page describes how to delete entities in bulk using\nthe managed bulk delete service. The\nDatastore mode 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 Datastore mode incurs one delete operation per entity deleted and some read operations based on a fraction of total entities 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 Datastore mode. **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 - [Datastore mode roles:](/datastore/docs/security/iam#predefined_rol es) `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 entities in your database and deletes them in batches. You may still query or read these entities while the results may vary based on the progress made. Bulk delete doesn't delete any entities added or modified after the operation starts.\n| **Note:** If you plan to delete all entities in the database, see the [database deletion feature](/datastore/docs/manage-databases#delete-database) instead.\n\n### Bulk delete specific kinds\n\n### gcloud\n\nTo bulk delete specific kinds, use the\n[`--collection-ids`](https://cloud.google.com/sdk/gcloud/reference/beta/firestore/bulk-delete#FLAGS) flag. The flag uses Firestore terminology, but a collection group ID is the same as a kind ID. The operation deletes only\nthe kinds with the given IDs.\n\nA kind\nincludes all entities and nested entities (at any path) with the specified\nkinds.\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, Datastore mode 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 entities:\n\n- `workEstimated` shows the estimated total number of bytes and entities an\n operation will process. Datastore mode might omit this metric if it\n can't make an estimate.\n\n- `workCompleted` shows the number of bytes and entities deleted so far.\n After the operation completes, the value shows the total number of\n bytes and entities 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 entities.\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 entity reads and deletes at the rates listed in [Datastore mode pricing](/datastore/pricing). Bulk delete operations incur one index entry read per entity found and one delete operation per entity deleted. You are charged one read operation for up to 1000 index entries read. For example, for a bulk delete operation that deleted 1500 entities, you will be charged with 2 entities reads and 1500 entity deletes.\n\n\u003cbr /\u003e\n\nNote that Datastore mode charges on the actual work done. If the\noperation is cancelled or failed due to user error, you will be charged with\nprogress made. Datastore mode won't charge reads or deletes for the\nentities that are not eventually deleted, such as entities 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](/datastore/docs/best-practices#deletions) which might slow down the queries.\n\n\nOther option\n------------\n\n[Dataflow](/dataflow) is a managed service for developing and executing\ndata processing workflows which can also bulk delete data. Dataflow provides a\nDatastore delete template that you can use to delete entities\nselected by a [GQL](/datastore/docs/reference/gql_reference) query.\n\nFor more information, see the [Dataflow documentation on executing the Datastore\nbulk delete template](/dataflow/docs/guides/templates/provided-utilities#datastore-bulk-delete).\n\nIf your use case involves data retention, see [Manage data retention with TTL policies](/datastore/docs/ttl)."]]