Guest User

Untitled

a guest
Jun 19th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. # This script can be used standalone
  2. # So it doesn't depend on filesystem or Google Cloud for the credentials
  3.  
  4. from google.cloud import firestore
  5. from google.oauth2 import service_account
  6.  
  7. key = 'your_credentials_json_string'
  8.  
  9. info = json.loads(key)
  10. creds = service_account.Credentials.from_service_account_info(info)
  11. db = firestore.Client(credentials=creds, project="project_name_goes_here")
  12.  
  13. # Upsert a document
  14. doc_ref = db.collection(u'collection_name').document(u'document_id')
  15. doc_ref.set({'attr': 'value'})
  16.  
  17. # Fetch all docs and print
  18. collection_ref = db.collection(u'd')
  19. docs = collection_ref.get()
  20. for doc in docs:
  21. print(u'{} => {}'.format(doc.id, doc.to_dict()))
  22.  
  23. # AFAIK, Python lib doesn't support real-time listening for document updates
Add Comment
Please, Sign In to add comment