我正在尝试迭代Firestore中的所有文档。我在Python中运行以下代码
from google.cloud.firestore import Client
client = Client()
docs = list()
for es in client.collection('exchange-statements').stream():
docs.append(es)但它会产生以下错误
google.api_core.exceptions.ServiceUnavailable: 503 The datastore operation timed out, or the data was temporarily unavailable.我正在使用google-cloud-firestore v1.2.0。
编辑
由于我的问题是关于流式文档,而不仅仅是计数,所以它与here的解决方案不同。
发布于 2019-07-02 17:46:51
受answer here的启发,我想出了一个通用的解决方案。然而,我想知道是否没有更好的解决方案。
def iterate(collection_name, batch_size=5000, cursor=None):
query = client.collection(collection_name).limit(batch_size).order_by('__name__')
if cursor:
query = query.start_after(cursor)
for doc in query.stream():
yield doc
if 'doc' in locals():
yield from iterate(collection_name, batch_size, doc)https://stackoverflow.com/questions/56842251
复制相似问题