Firestore updates using python api are not persisting
Question:
I have the following code.
from firebase_admin import firestore
db = firestore.client()
collection = db.collection('word_lists')
word_list = collection.get()
for item in word_list:
item_dict = item.to_dict()
print item_dict['next_practice_date']
item.reference.update({'next_practice_date': 0.0})
When I run the code the first time everything is fine, no errors. The second time I run it I expect all the prints to print 0.0
but instead many print None
, particularly the ones at the end. What is going on?
Answers:
I did not find the solution to the problem but instead switched from firebase_admin import firestore
to from google.cloud import firestore
and everything works well now.
from firebase_admin import firestore
db = firestore.client()
collection = db.collection('word_lists')
word_list = collection.get()
if not word_list.exists(): return
for item in word_list:
item_dict = item.to_dict()
print(item_dict['next_practice_date'])
item.reference.update({'next_practice_date': 0.0})
I have the following code.
from firebase_admin import firestore
db = firestore.client()
collection = db.collection('word_lists')
word_list = collection.get()
for item in word_list:
item_dict = item.to_dict()
print item_dict['next_practice_date']
item.reference.update({'next_practice_date': 0.0})
When I run the code the first time everything is fine, no errors. The second time I run it I expect all the prints to print 0.0
but instead many print None
, particularly the ones at the end. What is going on?
I did not find the solution to the problem but instead switched from firebase_admin import firestore
to from google.cloud import firestore
and everything works well now.
from firebase_admin import firestore
db = firestore.client()
collection = db.collection('word_lists')
word_list = collection.get()
if not word_list.exists(): return
for item in word_list:
item_dict = item.to_dict()
print(item_dict['next_practice_date'])
item.reference.update({'next_practice_date': 0.0})