Exporting data from Cloud Firestore to local emulator
Steps to export data from Cloud Firestore to local emulator.
1. Login to Firebase or Google Cloud:
firebase login
or
gcloud auth login
2. Connect to your project:
firebase use your-project-name
or
gcloud config set project your-project-name
3. Export your production data to the Google Cloud storage bucket folder:
gcloud firestore export gs://your-project-name.appspot.com/<your-choosen-folder-name>
4. Copy bucket folder to your local machine:
gsutil -m cp -r gs://your-project-name.appspot.com/<your-choosen-folder-name> /path/to/some/folder
Now we have production data in our local machine, but we need to make some modifications in order to make it available to emulators. Just follow these three simple steps.
First, switch to the newly created folder:
cd /path/to/some/folder
Rename the metadata file as firestore_export.overall_export_metadata:
mv your-choosen-folder-name.overall_export_metadata firestore_export.overall_export_metadata
And finally, copy all files to .emulator-data/firestore_export
in your workspace folder:
cp -R * /path/to/workspace/emulator/.emulator-data/firestore_export/
That's it! The next time you run emulators, Firestore will have all the imported data.
PreviousImporting existing data into local emulatorsNextExporting user accounts from Firebase to local emulator
Last updated
Was this helpful?