导出 Firestore 数据为 JSON 文件
Google 的 Firestore Console 无法将 Firestore 数据导出为 CSV/JSON 等格式的文件,经过调研,需要先将 Firestore 数据导出到 GCS,然后再导入 BigQuery 进行格式化,将格式化后的文件导出到 GCS,最后下载到本地。
也可以通过调用 SDK 的方式写代码进行导出。
导出步骤
以下命令都在 Google Cloud Shell 中执行。
创建一个 GCS Bucket 存放导出的数据:
1 | gcloud storage buckets create gs://warner/firestore-export |
创建一个 BigQuery 数据集:
1 | bq mk --dataset warner-firestore-export |
导出 Firestore 数据到 GCS Bucket:
1 | gcloud firestore export gs://warner/firestore-export/<collection_id> --collection-ids=<collection_id> |
导入 BigQuery 数据集中:
1 | # warner_firestore_export.<collection_id> 意思为 <数据集名称>.<表名称>,此处以 collection_id 作为表名 |
格式化为 JSON 并导出到 GCS Bucket 中:
1 | bq extract --destination_format NEWLINE_DELIMITED_JSON 'warner_firestore_export.<collection_id>' gs://warner/firestore-export/<collection_id>.json |
随后就可以在 UI 中进行下载,如果 JSON 文件较多,也可以通过命令批量拷贝,随后下载整个目录即可:
1 | mkdir firestore_json_files |
导出 Firestore 数据为 JSON 文件
https://warnerchen.github.io/2026/01/04/导出-Firestore-数据为-JSON-文件/
You need to set
install_url to use ShareThis. Please set it in _config.yml.