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:
- Go to my local Firebase project path.
- Start the emulators using:
firebase emulators:start - Create manually some mockup data using the GUI at http://localhost:4000/firestore using the buttons provided: + Start Collection and + Add Document.
- Export this data locally using:
emulators:export ./mydirectory - 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=myCollectionThe export is now located under Firebase Storage in a folder with a timestamp as name (I didn't use a prefix for my test) - Download this folder to local drive with:
gsutil cp -r gs://my-project-bucket-id.appspot.com/myCollection ./production_data_exportNOTE: 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 - Once downloaded, imitate the local export structure renaming the folder to
firestore_exportand copying thefirebase-export-metadata.jsonfile 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 - Finally, start the local emulator pointing to this production data to be imported:
firebase emulators:start --import=./mock_up_data/production_data_export/ - 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.