You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何修改Google Datastore中的Kind名称或删除Kind?

Hey there! Let me break down how to rename or delete a Kind in Google Datastore—since there’s no built-in one-click option for either, we’ll use practical workarounds that get the job done.

Renaming a Datastore Kind

Datastore doesn’t support renaming a Kind directly because the Kind name is a core attribute of every entity. Instead, you’ll need to migrate your data to a new Kind:

  • Step 1: Export all entities from the original Kind
    Use the Cloud SDK or Cloud Console to export your data. For the gcloud command:

    gcloud datastore export --kinds="OLD_KIND_NAME" gs://your-cloud-storage-bucket/path/
    

    This creates a backup of all entities from OLD_KIND_NAME in your Cloud Storage bucket.

  • Step 2: Update the exported metadata to rename the Kind
    Navigate to your Cloud Storage bucket and locate the exported files. You’ll need to:

    • Replace every instance of OLD_KIND_NAME with NEW_KIND_NAME in the index.yaml file (if you have indexes configured for the Kind).
    • Rename the folder structure under namespace/ from OLD_KIND_NAME to NEW_KIND_NAME (this is where the entity data is stored).
  • Step 3: Import the modified data back to Datastore
    Run the import command to bring the renamed entities into Datastore:

    gcloud datastore import gs://your-cloud-storage-bucket/path/[EXPORT_FOLDER]/
    

    Make sure to use the correct path to the exported folder (it’ll have a timestamp in the name).

  • Step 4: Verify and clean up
    Check the Cloud Console to confirm the new Kind has all your data. Once you’re sure everything’s migrated, delete all entities from the original Kind (follow the steps in the next section) to effectively remove it.

Deleting a Datastore Kind

Datastore doesn’t have a "delete Kind" button—Kinds are dynamic, meaning they disappear automatically once there are no entities left under them. Here’s how to clear out all entities:

  • For small datasets (few hundred entities)
    Head to the Cloud Console > Datastore > Entities, select the Kind you want to delete, check the box at the top to select all entities, then click the delete button. This works great for small volumes but isn’t efficient for large datasets.

  • For large datasets
    Use a client library or script to batch-delete entities. Here’s a quick Python example using the Google Cloud Datastore SDK:

    from google.cloud import datastore
    
    def delete_kind(kind_name):
        client = datastore.Client()
        query = client.query(kind=kind_name)
        query.keys_only()  # Fetch only keys to save bandwidth
    
        # Batch delete in chunks (Datastore limits batch size to 500)
        keys = []
        for key in query.fetch():
            keys.append(key)
            if len(keys) == 500:
                client.delete_multi(keys)
                keys = []
        if keys:
            client.delete_multi(keys)
    
    delete_kind("KIND_TO_DELETE")
    

    You can also use the gcloud datastore delete command with a filter, but scripting gives you more control over large batches.

  • Pro tip
    If you want to back up the Kind before deleting it, run the export command from the renaming section first—better safe than sorry!

内容的提问来源于stack exchange,提问作者Marcelo Boeira

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.27 09:18:01