首页 > 解决方案 > 导出 Firestore 集合数据、编辑和重新上传

问题描述

我创建了一个 Google Cloud 帐户并进行了所有设置,但由于某种原因,我无法弄清楚如何将我的 Firestore 数据导出到“文件”编辑/添加到该文件并重新上传。

我读了好几次: https ://firebase.google.com/docs/firestore/manage-data/export-import#import_specific_collections

没有代码,只是真正的混乱。我不确定如何导出集合以便进行批量编辑。

标签: firebasegoogle-cloud-firestore

解决方案


您可以使用 gcloud cli导出到云存储桶

gcloud beta firestore export gs://[BUCKET_NAME]

要导出到本地文件,您可以使用REST API

POST https://firestore.googleapis.com/v1beta1/{name=projects/*/databases/*}:exportDocuments

还有一个 npm 应用可以做到这一点,node-firestore-import-export

firestore-export --accountCredentials path/to/credentials/file.json --backupFile /backups/myDatabase.json
firestore-import --accountCredentials path/to/credentials/file.json --backupFile /backups/myDatabase.json

推荐阅读