Created
November 19, 2020 06:26
-
-
Save nwatab/44fab6efc9c71d0a5f6eb9ef79f3cf2c to your computer and use it in GitHub Desktop.
save firestore collections
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import firebase_admin | |
from firebase_admin import credentials | |
from firebase_admin import firestore | |
cred = credentials.Certificate('../your_project_credential.json') | |
firebase_admin.initialize_app(cred, { | |
'projectId': 'your_project_id' | |
}) | |
db = firestore.client() | |
data = [{'uid': doc.id, 'name': doc.to_dict()['name']} for doc in db.collection('your_collection').stream()] | |
data = sorted(data, key=lambda x: x['name'], ensure_ascii=False) # for multibyte | |
with open('data.json', 'w') as f: | |
f.write(data) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment