0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Firestoreのコレクション、サブコレクションを削除する(特にサブコレクションがある場合は注意)

0
Last updated at Posted at 2026-05-29

前提

  • コレクション内のドキュメントの全削除=コレクションの削除扱いになる
  • gcloud コマンドの bulk-delete はサブコレクションまで再帰的に削除してくれないので完全削除ができない
    ※collection-ids にサブコレクションを指定すれば削除できるが、同名のサブコレクションが全てのコレクションから横断的に削除される
  • サブコレクションまで再帰的に削除したい場合、 Firebase Cli が必要になる

コマンド

bulk-delete ( 非同期 )

サブコレクションを持っている場合、 bulk-delete だとサブコレクションの部分だけ残ってしまって完全に削除できない。

そのため、 Firebase Cli を入れて firebase コマンドから削除すること。

PROJECT_ID=xxxx

## 非同期 bulk-delete
gcloud firestore bulk-delete --async --project=${PROJECT_ID} \
--collection-ids="test_collection"

↑の状況確認

実行結果として、オペレーションIDがでるのでそれを引数に渡す。

gcloud firestore operations describe \
"projects/${PROJECT_ID}/databases/(default)/operations/xxxxxxxxxxxxxxxxxxxxx"

サブコレクションまで再帰的に削除する( Firebase Cli使用 )

指定されたコレクションを再帰的に強制削除していく。
※サブコレクションまで消してくれる

buld delete を先に実行してしまっていても実行可能。

PROJECT_ID=xxxx

firebase firestore:delete "collection_name" \
--project "${PROJECT_ID}" --database "(default)" \
--recursive --force
0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?