Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Firestore and Database Emulator: Initialization of an instance with a dataset #1167

Closed
gaeldestrem opened this issue Mar 12, 2019 · 41 comments · Fixed by #1968
Closed

Firestore and Database Emulator: Initialization of an instance with a dataset #1167

gaeldestrem opened this issue Mar 12, 2019 · 41 comments · Fixed by #1968

Comments

@gaeldestrem
Copy link

It would be great to have the possibility to create an instance of the Firestore emulator with a dataset.

Currently, we're doing a batch write to initialize or reset an instance of an emulator. The issue is that it takes nearly 3s for an update of 120 operations (our testing dataset).

Would it be possible to create a Firestore emulator instance from a snapshot or to improve the performances of the emulator for large updates?

@wyattades
Copy link

I agree that it would be great to load a database "snapshot" on initialization. I currently run the firestore and functions emulators locally for development, but when I seed the DB with testing data, a bunch of firestore function triggers are executed. This is pretty undesirable, so are there any plans for a feature to help with loading initial data or, even better, firestore data persistence to disk?

@samtstern
Copy link
Contributor

samtstern commented Oct 12, 2019 via email

@wyattades
Copy link

Yes that would be a good solution for now, thanks!

@anantanandgupta
Copy link

So there are no milestones set for this yet? but one thing I like now about this team here, it seems to be more active and responsive.

@anantanandgupta
Copy link

can guys please add realtime db also in scope for this along with firestore db.

@samtstern samtstern changed the title Firestore Emulator: Initialization of an instance with a dataset Firestore and Database Emulator: Initialization of an instance with a dataset Oct 14, 2019
@samtstern
Copy link
Contributor

@anantanandgupta no milestones yet, but yes we try to be really open about out progress! And I have added the Database emulator to be in scope as well. For Database the problem is easier (JSON format) but we still need to help you "pause" the Cloud Functions

@anantanandgupta
Copy link

anantanandgupta commented Oct 14, 2019

I know I am in good hands. But to tell you the criticality, I have designed this huge platform fully around firebase and everyone was against this a yesr back, but with my efforts i have proven till now that my decision to use firebase as the technology was not wrong. At this point it has become so big that to work on multiple features by multiple developers with a common database hosted on cloud has become impossible. So if each of us can work on a local copy of the database, it will be a lot easier and efficient.

@ryanpbrewster
Copy link
Contributor

The ability to import data into the Firestore emulator (i.e., initialize it with "seed" data) should be going out with the next release. It will be a bit manual at first, we'll add better tooling in subsequent releases.

Looking into what would be necessary for the Realtime Database emulator.

@SamyPesse
Copy link
Contributor

@ryanpbrewster is there any documentation on how to setup "seed" data ?

@samtstern
Copy link
Contributor

@SamyPesse this has been implemented inside the Emulator JAR itself (as @ryanpbrewster said) but we have not actually exposed an API through firebase-tools to do import so this isn't really something you can use yet.

Would you mind sharing how you'd expect this to work? Would you prefer a flag on the firebase command, a field in firebase.json or something else?

@ryanpbrewster
Copy link
Contributor

Importing and exporting data is currently implemented, but we haven't quite figured out how to make it easy to use these features. So keep in mind that we know these instructions are rough, and we're open to ideas about how to improve this:

Get an export

You can generate an export from your production Firestore instance, or from the local emulator.

Emulator export

Boot up the emulator and populate it with data however you'd like. Once you have your database in a state that you like, create an export:

curl "localhost:8080/emulator/v1/projects/ryanpbrewster-test:export" \
  -d '{"database": "projects/ryanpbrewster-test/databases/(default)","export_directory":"."}' \
  -H "Content-Type: application/json

which will dump the export onto your local filesystem in a directory like firestore_export_1576524691/

Production export

You'll need a Google Cloud Storage bucket. I'll use my test project's default AppEngine bucket ryanpbrewster-test.appspot.com. Run

gcloud firestore export gs://ryanpbrewster-test.appspot.com/firestore-export

and Firestore will dump a full copy of your production data into Google Cloud Storage. If you'd like, you can use the --collection-ids flag to limit the export to a specific set of collections.

Once it's done you can copy it onto your local filesystem (note that this is going to go poorly if you have a huge database):

gsutil cp -r gs://ryanpbrewster-test.appspot.com/firestore-export .

Import data

For now, the only way to import data into the emulator is via a command line flag:

java -jar ~/.cache/firebase/emulators/cloud-firestore-emulator-v1.10.2.jar \
  --seed_from_export=firestore_export_1576524691/firestore_export_1576524691.overall_export_metadata

If all goes well, the emulator will start up and have all of your data in it.

Note that the path it's expecting is the location of the .overall_export_metadata file, which should be at the top level of the export directory.

@prgwar
Copy link

prgwar commented Dec 25, 2019

I was able to emulate the firestore data from the export. Now If I try to start the firebase emulator suit. Firestore emulator is not working because the emulator is already running in the port. I tried even setting the FIRESTORE_EMULATOR_HOST variable its not recognizing. If the seed path can also be passed along the command while starting the emulator it will be much more helpful and reduce a lot of development time like firebase emulators:start --firestore_seed_from_export = \path\to\seed\file

@srolfe26
Copy link

+1 for @prgwar 's suggestion. How can I get the emulator suite to run using this startup firestore? Functions in the emulator use production because "⚠ functions: The Cloud Firestore emulator is not running, so calls to Firestore will affect production."

@samtstern
Copy link
Contributor

@prgwar thanks for your suggestion, we are currently working on deciding the API for specifying import/export from the firebase command. Using the jar directly is just a workaround and not something we actually expect developers to do in the long term.

@srolfe26 your issue sounds like a different one, you're running the Cloud Functions emulator but not the Firestore emulator. Try running firebase init emulators to initialize the Firestore emulator and then run firebase emulators:start again.

@amkoehler
Copy link

For any fellow WSL (1 or 2) users out there, you may have trouble connecting to the emulator from your browser. I added a --host 0.0.0.0 flag to the above command and that fixed the issue.

java -jar ~/.cache/firebase/emulators/cloud-firestore-emulator-v1.10.2.jar \
  --seed_from_export=firestore_export_1576524691/firestore_export_1576524691.overall_export_metadata \
  --host 0.0.0.0

@ryanpbrewster ryanpbrewster removed their assignment Jan 16, 2020
@samtstern samtstern self-assigned this Jan 28, 2020
@spencerwhyte
Copy link
Contributor

Would @prgwar 's suggestion of using --firestore_seed_from_export= be acceptable?

If so, I'm willing to put up a PR. How else can I help get the ball rolling?

I would also love if the same seed_from_export functionality could be implemented on the Realtime Database emulator.

@samtstern
Copy link
Contributor

@spencerwhyte thanks for the offer! I am actively tackling this right now, working on something that will support Firestore and RTDB and also any future emulators.

How would you feel about this general flow:

  • A "backup" is a folder that contains:
    • A bunch of individual emulator backups in their canonical formats
    • A single metadata.json file that describes them
  • To start the emulators with a seed you do: firebase emulators:start --import="./folder-with-backup"
  • To take a backup of the running emulators you open a new terminal while they are running and do firebase emulators:export

That's what I am currently working on, I think it's the most flexible thing but I am very open to feedback

@spencerwhyte
Copy link
Contributor

spencerwhyte commented Feb 11, 2020

@samtstern That's great to hear!

This design sounds perfect, just as long as the emulator export format / backup format is something that we can work with. If it's the same format as the backups on production, that'll do. We have a need to import a large amount of data for our integration tests without firing off our triggers. Currently we have been surviving by doing some checks that disable triggers when under test, however we'd love to avoid that complexity. This support for --import will allow us to simplify things.

We use firebase emulators:exec for our tests, so as long as it will work with exec as well, we'd be happy.

@samtstern
Copy link
Contributor

@spencerwhyte

  1. Yes we will definitely stick to the same formats as production whenever possible. So for Firestore we'll support the import/export format and for RTDB it will just be a giant json file.
  2. Yes we will support emulators:exec --import

Thanks for the feedback!

@samtstern
Copy link
Contributor

PR #1968 implements this feature (for Firestore only at the moment, Realtime Database coming soon) and will be included in the next CLI release (likely 7.14.0)

@samtstern
Copy link
Contributor

This feature was just released in 7.14.0 ... give it a try and let us know what you think! Right now it's Firestore only but Realtime Database is up next.

@shaimo
Copy link

shaimo commented Mar 8, 2020

Is this documented anywhere? Also, is there a way to export the production data without a Google Cloud Storage bucket (which I don't have)?
Having hard time testing triggers locally without data replicated from the cloud datastore.

@samtstern
Copy link
Contributor

@shaimo sorry we're a bit behind on docs but they should be out in the next few days!

To export from production you do need a Cloud Storage bucket. This is because export is a "managed" operation which means it happens on a Google server somewhere. We can't run an operation like that against your local filesystem, we need a cloud destination.

If you have a Firebase project you actually do have a default Cloud Storage bucket you can use and it includes some free quota. Just navigate over to the Storage section of the Firebase console to check it out.

@manwithsteelnerves
Copy link

manwithsteelnerves commented Mar 14, 2020

@samtstern As the documentation may take some time, can you please give a brief on how to import/export to emulator instance?

@samtstern
Copy link
Contributor

samtstern commented Mar 16, 2020

We now have some documentation on the new flags here:
https://firebase.google.com/docs/emulator-suite/install_and_configure#startup

But let me give you an example anyway. To use import/export you will need two terminal windows so let's call them Terminal 1 and Terminal 2

First start the emulators

Terminal 1

$ firebase emulators:start
# ...

After you have built up some data in them that you would like to save, run the export command in another terminal:

Terminal 2

$ firebase emulators:export ./mydirectory
# ...

Now you have an export in ./mydirectory. Next time you start the emulators, tell them to import from there:

Terminal 1

$ firebase emulators:start --import=./mydirectory
# ...

And that's it!

@landonj
Copy link

landonj commented Mar 16, 2020

@samtstern Can we import from a production export using the firebase emulators:start --import command?
I see that emulators:start --import is looking for firebase-export-metadata.json but I have firestore-export/firestore-export.overall_export_metadata

@samtstern
Copy link
Contributor

@landonj you can but it's a little tricky at the moment. The simplest thing to do is run emulators:export once and then modify the JSON files to point to your production export rather than the local one.

@FergyKay
Copy link

Anything on seeding RTDB for emulator yet?

@samtstern
Copy link
Contributor

samtstern commented Mar 30, 2020

@FergyKay nothing yet but you can follow along here:
#2079

@jQrgen
Copy link

jQrgen commented Apr 6, 2020

This is much needed

@Ridermansb
Copy link

Ridermansb commented May 31, 2020

I'm trying to do the exact same thing as @landonj ..

and I tried what @samtstern told ... but I'm receiving an error...

What I'm doing wrong ?

bdw.. the file exists!

firebase emulators:start --debug --only firestore,functions --import=/Users/ridermansb/Projects/meve.ai/backups/emulator-data

[2020-05-31T13:31:23.601Z] com.google.cloud.datastore.core.exception.DatastoreException: Failed to parse overall export metadata file
at com.google.cloud.datastore.emulator.impl.ExportImportUtil.parseOverallMetadataFile(ExportImportUtil.java:225)
at com.google.cloud.datastore.emulator.impl.ExportImportUtil.fetchEntities(ExportImportUtil.java:54)
at com.google.cloud.datastore.emulator.firestore.CloudFirestore.main(CloudFirestore.java:89)
{"metadata":{"emulator":{"name":"firestore"},"message":"com.google.cloud.datastore.core.exception.DatastoreException: Failed to parse overall export metadata file\n\tat com.google.cloud.datastore.emulator.impl.ExportImportUtil.parseOverallMetadataFile(ExportImportUtil.java:225)\n\tat com.google.cloud.datastore.emulator.impl.ExportImportUtil.fetchEntities(ExportImportUtil.java:54)\n\tat com.google.cloud.datastore.emulator.firestore.CloudFirestore.main(CloudFirestore.java:89)\n"}}
[2020-05-31T13:31:23.602Z] Caused by: java.io.FileNotFoundException: /Users/ridermansb/Projects/meve.ai/backups/emulator-data/Users/ridermansb/Projects/meve.ai/backups/2020-05-31/2020-05-31/2020-05-31T13:19:28_6168.overall_export_metadata (No such file or directory)
{"metadata":{"emulator":{"name":"firestore"},"message":"Caused by: java.io.FileNotFoundException: /Users/ridermansb/Projects/meve.ai/backups/emulator-data/Users/ridermansb/Projects/meve.ai/backups/2020-05-31/2020-05-31/2020-05-31T13:19:28_6168.overall_export_metadata (No such file or directory)\n"}}
[2020-05-31T13:31:23.603Z] at java.base/java.io.FileInputStream.open0(Native Method)
at java.base/java.io.FileInputStream.open(FileInputStream.java:213)
at java.base/java.io.FileInputStream.(FileInputStream.java:155)
at com.google.cloud.datastore.emulator.impl.ExportImportUtil.parseOverallMetadataFile(ExportImportUtil.java:215)
... 2 more
{"metadata":{"emulator":{"name":"firestore"},"message":"\tat java.base/java.io.FileInputStream.open0(Native Method)\n\tat java.base/java.io.FileInputStream.open(FileInputStream.java:213)\n\tat java.base/java.io.FileInputStream.(FileInputStream.java:155)\n\tat com.google.cloud.datastore.emulator.impl.ExportImportUtil.parseOverallMetadataFile(ExportImportUtil.java:215)\n\t... 2 more\n"}}

Error: firestore: Firestore Emulator has exited with code: 1

@gugahoi
Copy link

gugahoi commented Jun 1, 2020

@landonj you can but it's a little tricky at the moment. The simplest thing to do is run emulators:export once and then modify the JSON files to point to your production export rather than the local one.

Can you expand on this? Can I point directly to the gcloud bucket? Or must I first download the contents of the export locally? Which files do I need to modify?

The following is what I have attempted:

> firebase emulators:start
> firebase emulators:export ~/emulator-data/
> # close the emulator
> gcloud firestore export gs://xxxxx-xxxxx-xxxxx/emulator/
> gsutil cp -r gs://xxxxx-xxxxx-xxxxx/emulator ~/emulator-data/
> firebase emulators:start --only firestore --import /home/gugahoi/emulator-data/emulator/ --debug
[2020-06-01T10:04:36.492Z] > command requires scopes: ["email","openid","https://www.googleapis.com/auth/cloudplatformprojects.readonly","https://www.googleapis.com/auth/firebase","https://www.googleapis.com/auth/cloud-platform"]
[2020-06-01T10:04:36.493Z] > authorizing via signed-in user
i  emulators: Starting emulators: firestore {"metadata":{"emulator":{"name":"hub"},"message":"Starting emulators: firestore"}}
[2020-06-01T10:04:36.510Z] [hub] writing locator at /tmp/hub-flux-development.json
i  emulators: Shutting down emulators. {"metadata":{"emulator":{"name":"hub"},"message":"Shutting down emulators."}}
i  hub: Stopping emulator hub {"metadata":{"emulator":{"name":"hub"},"message":"Stopping emulator hub"}}
[2020-06-01T10:04:36.825Z] Error: ENOENT: no such file or directory, open '/home/gugahoi/emulator-data/emulator/firebase-export-metadata.json'
    at Object.openSync (fs.js:458:3)
    at Object.readFileSync (fs.js:360:35)
    at Object.<anonymous> (/home/gugahoi/.nvm/versions/node/v12.16.3/lib/node_modules/firebase-tools/lib/emulator/controller.js:183:44)
    at Generator.next (<anonymous>)
    at fulfilled (/home/gugahoi/.nvm/versions/node/v12.16.3/lib/node_modules/firebase-tools/lib/emulator/controller.js:5:58)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)

Error: An unexpected error has occurred.

As the above did not seem to work, I updated the firebase-exports-metadata.json file with the following contents:

> cat firebase-export-metadata.json
{"version":"8.4.1","firestore":{"version":"1.11.4","path":"emulator","metadata_file":"emulator/emulator.overall_export_metadata"}}

Below is the directory structure:

gugahoi:~/emulator-data > tree .
.
├── emulator
│   ├── all_namespaces
│   │   └── all_kinds
│   │       ├── all_namespaces_all_kinds.export_metadata
│   │       ├── output-0
│   │       └── output-1
│   └── emulator.overall_export_metadata
├── firebase-export-metadata.json
├── firebase-export-metadata.json.bak
└── firestore_export
    └── firestore_export.overall_export_metadata

However I still have no data in the emulator UI.

Edit

Just thought I'd add the final output from the emulator, it runs without error but without my data:

> firebase emulators:start --only firestore --import /home/gugahoi/emulator-data/ --debug
[2020-06-01T11:31:34.256Z] > command requires scopes: ["email","openid","https://www.googleapis.com/auth/cloudplatformprojects.readonly","https://www.googleapis.com/auth/firebase","https://www.googleapis.com/auth/cloud-platform"]
[2020-06-01T11:31:34.257Z] > authorizing via signed-in user
i  emulators: Starting emulators: firestore {"metadata":{"emulator":{"name":"hub"},"message":"Starting emulators: firestore"}}
[2020-06-01T11:31:34.274Z] [hub] writing locator at /tmp/hub-flux-development.json
i  firestore: Importing data from /home/gugahoi/emulator-data/emulator/emulator.overall_export_metadata {"metadata":{"emulator":{"name":"firestore"},"message":"Importing data from /home/gugahoi/emulator-data/emulator/emulator.overall_export_metadata"}}
[2020-06-01T11:31:34.302Z] Ignoring unsupported arg: projectId {"metadata":{"emulator":{"name":"firestore"},"message":"Ignoring unsupported arg: projectId"}}
[2020-06-01T11:31:34.303Z] Ignoring unsupported arg: auto_download {"metadata":{"emulator":{"name":"firestore"},"message":"Ignoring unsupported arg: auto_download"}}
[2020-06-01T11:31:34.303Z] Starting Firestore Emulator with command {"binary":"java","args":["-Duser.language=en","-jar","/home/gugahoi/.cache/firebase/emulators/cloud-firestore-emulator-v1.11.4.jar","--host","localhost","--port",8080,"--seed_from_export","/home/gugahoi/emulator-data/emulator/emulator.overall_export_metadata","--rules","/home/gugahoi/projects/flux/flux/firestore.rules"],"optionalArgs":["port","webchannel_port","host","rules","functions_emulator","seed_from_export"],"joinArgs":false} {"metadata":{"emulator":{"name":"firestore"},"message":"Starting Firestore Emulator with command {\"binary\":\"java\",\"args\":[\"-Duser.language=en\",\"-jar\",\"/home/gugahoi/.cache/firebase/emulators/cloud-firestore-emulator-v1.11.4.jar\",\"--host\",\"localhost\",\"--port\",8080,\"--seed_from_export\",\"/home/gugahoi/emulator-data/emulator/emulator.overall_export_metadata\",\"--rules\",\"/home/gugahoi/projects/flux/flux/firestore.rules\"],\"optionalArgs\":[\"port\",\"webchannel_port\",\"host\",\"rules\",\"functions_emulator\",\"seed_from_export\"],\"joinArgs\":false}"}}
i  firestore: Firestore Emulator logging to firestore-debug.log {"metadata":{"emulator":{"name":"firestore"},"message":"Firestore Emulator logging to \u001b[1mfirestore-debug.log\u001b[22m"}}
[2020-06-01T11:31:35.197Z] API endpoint: http://localhost:8080
 {"metadata":{"emulator":{"name":"firestore"},"message":"API endpoint: http://localhost:8080\n"}}
[2020-06-01T11:31:35.198Z] If you are using a library that supports the FIRESTORE_EMULATOR_HOST environment variable, run:

   export FIRESTORE_EMULATOR_HOST=localhost:8080

Dev App Server is now running.

 {"metadata":{"emulator":{"name":"firestore"},"message":"If you are using a library that supports the FIRESTORE_EMULATOR_HOST environment variable, run:\n\n   export FIRESTORE_EMULATOR_HOST=localhost:8080\n\nDev App Server is now running.\n\n"}}
[2020-06-01T11:31:35.322Z] Ignoring unsupported arg: auto_download {"metadata":{"emulator":{"name":"ui"},"message":"Ignoring unsupported arg: auto_download"}}
[2020-06-01T11:31:35.322Z] Ignoring unsupported arg: port {"metadata":{"emulator":{"name":"ui"},"message":"Ignoring unsupported arg: port"}}
[2020-06-01T11:31:35.323Z] Starting Emulator UI with command {"binary":"node","args":["/home/gugahoi/.cache/firebase/emulators/ui-v1.0.0/server.bundle.js"],"optionalArgs":[],"joinArgs":false} {"metadata":{"emulator":{"name":"ui"},"message":"Starting Emulator UI with command {\"binary\":\"node\",\"args\":[\"/home/gugahoi/.cache/firebase/emulators/ui-v1.0.0/server.bundle.js\"],\"optionalArgs\":[],\"joinArgs\":false}"}}
i  ui: Emulator UI logging to ui-debug.log {"metadata":{"emulator":{"name":"ui"},"message":"Emulator UI logging to \u001b[1mui-debug.log\u001b[22m"}}
[2020-06-01T11:31:35.395Z] Web / API server started at http://localhost:4000
 {"metadata":{"emulator":{"name":"ui"},"message":"Web / API server started at http://localhost:4000\n"}}

┌───────────────────────────────────────────────────────────────────────┐
│ ✔  All emulators ready! View status and logs at http://localhost:4000 │
└───────────────────────────────────────────────────────────────────────┘

┌───────────┬────────────────┬─────────────────────────────────┐
│ Emulator  │ Host:Port      │ View in Emulator UI             │
├───────────┼────────────────┼─────────────────────────────────┤
│ Firestore │ localhost:8080 │ http://localhost:4000/firestore │
└───────────┴────────────────┴─────────────────────────────────┘
  Other reserved ports: 4400, 4500

Issues? Report them at https://github.com/firebase/firebase-tools/issues and attach the *-debug.log files.

@bkuri
Copy link

bkuri commented Jun 7, 2020

@gugahoi your post helped me come up with a solution: https://gist.github.com/bkuri/36cef71bcf30a5416b1c353cb81f38ed

It's a small bash script that seeds your cloud storage emulator instance. All it needs is the project name and a destination path to save exported data to. ie: ./seed-storage.sh my-project /tmp/export.

BTW, the above script depends on two very common tools (lsof and screen) in addition to the usual suspects (firebase, gcloud and gsutil), so make sure you have them installed.

Hope this helps someone. 👍

@manwithsteelnerves
Copy link

Anyway to avoid triggering of firestore functions on importing an existing database?

@gugahoi
Copy link

gugahoi commented Jun 15, 2020

@bkuri thanks for that script, I guess there is something odd going on with my setup/installation as I am still unable to get any data to show up in the firestore emulator console.

@metafaniel
Copy link

metafaniel commented Jun 24, 2020

Thanks to @gugahoi I was able to import a collection from production into the local emulator.
To do so I did the following steps:

  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_myCollection
        │       ├── all_namespaces_kind_myCollection.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.

@gugahoi
Copy link

gugahoi commented Jun 24, 2020

Just as a brief update: when I posted the instructions from the comment above, I was doing it in WSL2 and they didn't seem to work but the same steps in Ubuntu seem to be fine.I suspect there might be something in WSL2 interfering.

@nvanhoesel
Copy link

I want to do this the other way around i want to import my emulator data into production, I need to add 7000 google sheet rows to my firestore and i was able to do that by editing a function however when trying to do it in production my memory limit gets exceeded also when something goes wrong inside the function i might end up with duplicate data. I noticed the export import and i noticed that i can make an export of my local emulator firestore data. But how about importing my local backup into production ?

@samtstern
Copy link
Contributor

@nvanhoesel the import/export formats are the same in production and in the emulators. But yours is an uncommon use case so you'll need to do some work yourself to get the emulator export into Google Cloud Storage so that Firestore can import it properrly.

@cedvdb
Copy link

cedvdb commented Feb 8, 2022

Is there a way to reset it to initial imported data while it is running, like an endpoint that can be called from code ? How do people even run integration tests without this ?

@DiegoGonzalezCruz
Copy link

Is this still working? I'm getting errors exit code 1.
If I import just a few collections , it works fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.