Skip to main content
Less chatty
Source Link
halfer
  • 20.2k
  • 20
  • 110
  • 207

I wish these instructions were clear enough to be helpful. I hope this will help someoneThis should assist readers for now, while we wait forawait a more robust solution from the Firebase folks.

I wish these instructions were clear enough to be helpful. I hope this will help someone while we wait for a more robust solution from the Firebase folks.

This should assist readers for now, while we await a more robust solution from the Firebase folks.

Supress project info
Source Link
Metafaniel
  • 30.9k
  • 8
  • 45
  • 70
$ tree . . ├── local_data_export │ ├── firebase-export-metadata.json │ └── firestore_export │ ├── all_namespaces │ │ └── all_kinds │ │ ├── all_namespaces_all_kinds.export_metadata │ │ └── output-0 │ └── firestore_export.overall_export_metadata └── production_data_export ├── firebase-export-metadata.json └── firestore_export ├── all_namespaces │ └── kind_logsRedeemkind_myCollection │ ├── all_namespaces_kind_logsRedeemall_namespaces_kind_myCollection.export_metadata │ ├── output-0 │ └── output-1 └── firestore_export.overall_export_metadata 8 directories, 9 files 
$ tree . . ├── local_data_export │ ├── firebase-export-metadata.json │ └── firestore_export │ ├── all_namespaces │ │ └── all_kinds │ │ ├── all_namespaces_all_kinds.export_metadata │ │ └── output-0 │ └── firestore_export.overall_export_metadata └── production_data_export ├── firebase-export-metadata.json └── firestore_export ├── all_namespaces │ └── kind_logsRedeem │ ├── all_namespaces_kind_logsRedeem.export_metadata │ ├── output-0 │ └── output-1 └── firestore_export.overall_export_metadata 8 directories, 9 files 
$ tree . . ├── local_data_export │ ├── firebase-export-metadata.json │ └── firestore_export │ ├── all_namespaces │ │ └── all_kinds │ │ ├── all_namespaces_all_kinds.export_metadata │ │ └── output-0 │ └── firestore_export.overall_export_metadata └── production_data_export ├── firebase-export-metadata.json └── firestore_export ├── all_namespaces │ └── kind_myCollection │ ├── all_namespaces_kind_myCollection.export_metadata │ ├── output-0 │ └── output-1 └── firestore_export.overall_export_metadata 8 directories, 9 files 
Source Link
Metafaniel
  • 30.9k
  • 8
  • 45
  • 70

My method is somewhat manual but it does the trick. I've shared it in this useful Github thread but I'll list the steps I did here if you find them useful:

  1. Go to my local Firebase project path.
  2. Start the emulators using: firebase emulators:start
  3. Create manually some mockup data using the GUI at http://localhost:4000/firestore using the buttons provided: + Start Collection and + Add Document.
  4. Export this data locally using: emulators:export ./mydirectory
  5. About the project data located at Firebase Database / Cloud Firestore, I exported a single collection like this: gcloud firestore export gs://my-project-bucket-id.appspot.com --collection-ids=myCollection The export is now located under Firebase Storage in a folder with a timestamp as name (I didn't use a prefix for my test)
  6. Download this folder to local drive with: gsutil cp -r gs://my-project-bucket-id.appspot.com/myCollection ./production_data_export NOTE: I did this in a Windows environment... gsutil will throw this error: "OSError: The filename, directory name, or volume label syntax is incorrect" if the folder has invalid characters for a folder name in Windows (i.e. colons) or this error: "OSError: Invalid argument.9.0 B]" if an inner file in the folder has invalid characters too. To be able to download the export locally, rename these with a valid Windows name (i.e. removing the colons) like this: gsutil mv gs://my-project-bucket-id.appspot.com/2020-05-22T02:01:06_86152 gs://my-project-bucket-id.appspot.com/myCollection
  7. Once downloaded, imitate the local export structure renaming the folder to firestore_export and copying the firebase-export-metadata.json file from the local export folder. Just to be visual, here's the structure I got:
$ tree . . ├── local_data_export │ ├── firebase-export-metadata.json │ └── firestore_export │ ├── all_namespaces │ │ └── all_kinds │ │ ├── all_namespaces_all_kinds.export_metadata │ │ └── output-0 │ └── firestore_export.overall_export_metadata └── production_data_export ├── firebase-export-metadata.json └── firestore_export ├── all_namespaces │ └── kind_logsRedeem │ ├── all_namespaces_kind_logsRedeem.export_metadata │ ├── output-0 │ └── output-1 └── firestore_export.overall_export_metadata 8 directories, 9 files 
  1. Finally, start the local emulator pointing to this production data to be imported: firebase emulators:start --import=./mock_up_data/production_data_export/
  2. You should see the imported data at: http://localhost:4000/firestore/

I wish these instructions were clear enough to be helpful. I hope this will help someone while we wait for a more robust solution from the Firebase folks.