How to export data from Cloud Firestore to file?

Viewed 1458

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

1 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.

Related