1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Firestore(Datastore mode)の全Kindのエンティティを一括削除する

Last updated at Posted at 2021-02-06

Firestore(Datastore mode)のKindのエンティティを一括削除したい場合、昔はコンソールのDatastore Adminから実行することが出来ましたが、現在はCloud DataflowのDatastore Bulk Deleteテンプレートを使用する手順となっています。

本記事ではCloud DataflowのDatastore Bulk Deleteテンプレートを使用して、一度に全Kindの全てのエンティティを削除する方法を記します。

手順

  1. コンソールのDataflow→「ジョブ」画面から「テンプレートからジョブを作成」をクリック
  2. 必要パラメータを入力

    パラメータ

    • ジョブ名: 任意
    • リージョン: Firestoreのリージョンを選択
    • Dataflowテンプレート: Bulk Delete Entities in Datastore
    • GQL Query: SELECT * WHERE __key__ < Key(__Stat, '0')
    • Read data from Datastore Project Id of: 削除したいFirestoreのプロジェクトID
    • Delete all matching entities from the GQL Query present in this Datastore Project IdRead data from Datastore Project id...: 同上
    • 一時的なロケーション: 適当なGCSバケット作ってそのパス+プレフィクス(任意)を指定
  3. 「ジョブを実行」をクリック

以上です。

GQLにKindlessクエリというKindを指定しないクエリを指定するのがミソです。
WHERE句は未指定だと統計用Kindを削除しに行って The kind "__Stat_Kind_CompositeIndex__" is reserved というエラーが出るので、それを避ける為のおまじないです^^

参考

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?