Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # This script can be used standalone
- # So it doesn't depend on filesystem or Google Cloud for the credentials
- from google.cloud import firestore
- from google.oauth2 import service_account
- key = 'your_credentials_json_string'
- info = json.loads(key)
- creds = service_account.Credentials.from_service_account_info(info)
- db = firestore.Client(credentials=creds, project="project_name_goes_here")
- # Upsert a document
- doc_ref = db.collection(u'collection_name').document(u'document_id')
- doc_ref.set({'attr': 'value'})
- # Fetch all docs and print
- collection_ref = db.collection(u'd')
- docs = collection_ref.get()
- for doc in docs:
- print(u'{} => {}'.format(doc.id, doc.to_dict()))
- # AFAIK, Python lib doesn't support real-time listening for document updates
Add Comment
Please, Sign In to add comment