Firebase Emulator Suite: Using production data inside the emulator
Alex Mammay
Posted on July 12, 2020
So you have a lot of info in your live (prod/test) database that you want to use with the new fancy firebase emulator UI. Here is how i went upon wiring up the data.
- Create storage bucket to sync into
gsutil mb gs://[targetstoragebucket]
- Export your prod database into a storage bucket.
- export the database with this command https://cloud.google.com/sdk/gcloud/reference/beta/firestore/export as a sample if you want to sync the whole database you can do
gcloud beta firestore export gs://[targetstoragebucket]
and you can pick and choose root level collections by doinggcloud beta firestore export gs://[targetstoragebucket] --collection-ids='customers','orders'
- export the database with this command https://cloud.google.com/sdk/gcloud/reference/beta/firestore/export as a sample if you want to sync the whole database you can do
- Create seed-data folder in your working directory
mkdir seed-data
- Once the export is done, we can sync it down to our filesystem.
gsutil rsync -r gs://[targetstoragebucket] seed-data/
- Now here is where we need to do a bit of patching, if we just try to run
firebase emulators:start --only firestore --import seed-data
it will error on us, so lets do a bit of cleaning up - lets
cd seed-data
and thenmkdir firestore_export
andtouch firebase-export-metadata.json
and then finally move our export into the firestore export folder, in my case it wasmv 2020-07-12T02:45:39_47881/ firestore_export
. - create content of firebase-export-metadata.json file, so lets open it in a editor and point out some important bits
{
"version": "8.5.0",
"firestore": {
"version": "1.11.4",
"path": "firestore_export",
"metadata_file": "firestore_export/2020-07-12T02:45:39_47881/2020-07-12T02:45:39_47881.overall_export_metadata"
}
}
make sure to note the version field (version of firebase-tools you are using, and the metadata file, this is that folder we used the mv
command for.
and just as final screen shot of the important stuff in case you want to compare.
now if we boot up the emulator with firebase emulators:start --only firestore --import seed-data
lets do a compare of the live database and our emulator
Woow!
💖 💪 🙅 🚩
Alex Mammay
Posted on July 12, 2020
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.
Related
firebase FieldValue.arrayUnion() called with invalid data. Nested arrays are not supported
August 26, 2020