I am developing an iOS app with Firebase. The development works well with remote Firestore cloud data.
Since I have to develop Firebase Functions, as advised in Firebase document, I started to use local emulator to develop Functions.
In order to develop Functions in local Firebase emulator, local Firestore has to be used.
So I ended up developing the app with local Firestore too. I created a lot of collections/documents in local Firestore.
Later, I realized I cannot move the data in local Firestore to my original Firestore Cloud. I found articles explaining how to export remote data and import it into local but not the reverse direction (local -> remote).
Am I missing something here? Or am I making some wrong assumptions in the development setup?
2
Answers
No.
Yes.
The emulator is a completely different piece of software than the cloud hosted service and just used for local testing and debugging. There is no synchronization between them. If you want to do that, you should use the Firebase Admin SDK to and write code to copy data between the two as you need it. You will have to query for all the documents in the emulator, then add those documents to the cloud hosted service.
As Doug said, you likely need to write a script to extract data from the emulator and then load it into the cloud.
Firestore-to-JSON: I have this "JavaScript/Node command-line script" that uses the Client SDK (not the Admin SDK) to extract all of the documents from one collection and write it to a local JSON text file. Read the comments at the start of the file as to how to configure and how to run the script.
JSON-to-Firestore: I also have this script that can be used to load a JSON file’s data (an array of documents) into a Firestore collection. Again, read the comments at the start of the file as to how to configure and how to run the script.
The two scripts certainly can be improved in many ways (e.g. stream the data into/out of the JSON files instead of loading it all into memory), but they do "show the way".