A minimal toolkit for seeding, importing, and exporting firestore data as JSON files.
Any read or write to firebase's services count against your free or paid tier limit. You probably will not hit anywhere near your limits during tests, but be sure to test with small data sets before committing to a full data import or export based on your desired data content needs and size.
1. git clone https://github.com/michaelmcshinsky/firestore-import-export.git
2. cd firestore-import-export
3. yarn install
- Navigate to the firebase console for your firbase app.
- Go to your Project Settings page.
- Scroll to Your Apps and copy the
databaseUrl
value in the configuration object. It should look similar to:https://<db-url>.firebaseio.com
. - Copy the value into the
constants.example.js
file for thedatabaseUrl
key. - Rename
constants.example.json
toconstants.json
.
- Navigate to the firebase console for your firbase app.
- Go to your Project Settings page and click on the Service Accounts tab.
- Click on the Generate New Private Key button. This will download a JSON file with your key information.
- Copy this information into the
service_key.example.json
file provided in the repo. - Rename
service_key.example.json
toservice_key.json
.
The import tool will take all of your JSON files from the uploads
folder and create collections using the file name and array data.
If you do not provide IDs, a second write operation will occur and set the docRef.id
as the id
of the document.
To run the importer, do the following:
- Add any JSON files to the
uploads
folder. It should be formatted as an array of objects. - Run the command:
yarn upload
- Feel like a winner because you didn't hand write out documents in the firebase console!
To run the exporter, do the following:
yarn download
NOTE: Running yarn download
will export every collection in your firestore.
If you wish to export specific collections, modify download.js
to take an array of names instead of querying the firstore for all collections.
Passing arguments after yarn download
will skip querying for all firestore collections and instead only download collections you name in the terminal.
yarn download <collectionName1> <collectionName2>