Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to export data from Cloud Firestore to file?

I have an application programmed in Flutter and I use Firebase to collect some information sent by users. The question is how can I transfer this information to my computer in the form of a file (JSON, TEXT, etc.) data like this picture:

enter image description here


2 Answers

Currently, Firestore does not support exporting existing data to a readable file but Firestore do have a managed Exporting and importing data that allows you to dump your data into a GCS bucket. It produces a format that is the same as Cloud Datastore uses. This means you can then import it into BigQuery.

However, community created a workaround for this limitation. You can use npm if you have installed it in your system. Below are the instructions to export the Firestore Data to JSON file using npm.

  1. Generate a private key file for your service account. In the Firebase console, open Settings > Service Accounts.

  2. Click Generate New Private Key, then confirm by clicking Generate Key.

  3. Securely store the JSON file containing the key. You may also check this documentation.

  4. Rename the JSON file to credentials.json.

  5. Enter the below code to your console:

npx -p node-firestore-import-export firestore-export -a credentials.json -b backup.json
  1. Follow the instructions prompted on your console.

You could also use this to import data to Firestore using below command:

npx -p node-firestore-import-export firestore-import -a credentials.json -b backup.json

Below are the results using npm from the package:

Firestore Collection: collection

Console: console

backup.json:

{"__collections__":{"test":{"Lq8u3VnOKvoFN4r03Ri1":{"test":"test","__collections__":{}}}}}

You can find more information regarding the package here.

like image 60
Marc Anthony B Avatar answered Sep 15 '25 08:09

Marc Anthony B


The package mentioned by @marc node-firestore-import-export in above answer has a flaw in case your database is very large.

This flaw is documented here https://github.com/jloosli/node-firestore-import-export/issues/815

For this reason I would recommend using https://github.com/benyap/firestore-backfire

like image 36
Adarsh Madrecha Avatar answered Sep 15 '25 08:09

Adarsh Madrecha