尝试从 Google Cloud Firestore 检索所有文档时如何处理超时错误?
How to deal with timeout errors when trying to retrieve all documents from Google Cloud Firestore?
给定 the example from Cloud Firestore documentation,假设我想收集城市的所有人口数量,我会这样做:
docs = db.collection("cities").stream()
populations = {}
for doc in docs:
doc_dict = doc.to_dict()
populations[doc_dict["name"]] = doc_dict["population"]
但是我的情况下文件太多,导致我得到google.api_core.exceptions.ServiceUnavailable: 503 数据存储操作超时,或者数据暂时不可用.
我查看了 and Is it possible to increase the response timeout in Google App Engine? 的答案,我了解到我无法更改超时期限。
这给我留下了一个问题:我怎样才能得到所有的人口数量?文档 ID 不是递增的,所以我记不住 "where I was before timeout",而且我没有从 Firestore 文档中找到类似 "cursor" 的解决方案。
Cloud Firestore 支持分页。 documentation 中甚至还有一个 python 代码示例。您需要注意有关使用文档快照定义查询游标的部分。
给定 the example from Cloud Firestore documentation,假设我想收集城市的所有人口数量,我会这样做:
docs = db.collection("cities").stream()
populations = {}
for doc in docs:
doc_dict = doc.to_dict()
populations[doc_dict["name"]] = doc_dict["population"]
但是我的情况下文件太多,导致我得到google.api_core.exceptions.ServiceUnavailable: 503 数据存储操作超时,或者数据暂时不可用.
我查看了
这给我留下了一个问题:我怎样才能得到所有的人口数量?文档 ID 不是递增的,所以我记不住 "where I was before timeout",而且我没有从 Firestore 文档中找到类似 "cursor" 的解决方案。
Cloud Firestore 支持分页。 documentation 中甚至还有一个 python 代码示例。您需要注意有关使用文档快照定义查询游标的部分。