Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. import firebase_admin
  2. from firebase_admin import credentials
  3. from firebase_admin import firestore
  4. import traceback
  5. import json
  6. cred = credentials.Certificate(constants.path_to_json)
  7. default_app = firebase_admin.initialize_app(cred)
  8. other_app = firebase_admin.initialize_app(cred, name='other')
  9. db = firestore.client()
  10. match_id = 'blala'
  11. pool_id = 'pidxyz'
  12. cont_team_id = '229'
  13.  
  14. doc_ref = db.collection('match-pools')
  15. .document(match_id)
  16. .collection('pid')
  17. .document(pool_id)
  18. .collection('contestant-teams')
  19. .document(cont_team_id)
  20.  
  21. def create_counter(ref, num_shards):
  22. batch = db.batch()
  23. print(batch)
  24. # Initialize the counter document
  25. batch.set(ref, { num_shards: num_shards })
  26. # Initialize each shard with count=0
  27. for i in range(0, num_shards):
  28. shardRef = ref.collection('shards').doc(i.to_string())
  29. batch.set(shardRef, { count: 0 })
  30. # Commit the write batch
  31. return batch.commit()
  32.  
  33. create_counter(doc_ref, 5)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement