【发布时间】:2019-06-21 09:36:33
【问题描述】:
我在 Google Cloud Firestore 中有一个集合 data。这个集合有超过 200K 的文档。我想将每个文档作为一行导出到文件中。
我创建了一个适用于 50K 行的脚本。之后它崩溃并出现以下异常。如何获取所有文件?
我看到了一个叫做偏移的东西,但不确定它对我的情况有帮助。
代码片段:
from google.cloud import firestore
import os
os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = "key.json"
db = firestore.Client()
col = db.collection(u'data')
docs = col.get()
with open('data.bak', 'a') as f:
for doc in docs:
f.write(u'{} => {}'.format(doc.id, doc.to_dict()))
f.write('\n')
例外:
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "down_db.py", line 13, in <module>
for doc in docs:
File "/usr/local/lib/python3.6/dist-packages/google/cloud/firestore_v1beta1/query.py", line 744, in get
for index, response_pb in enumerate(response_iterator):
File "/usr/local/lib/python3.6/dist-packages/google/api_core/grpc_helpers.py", line 81, in next
six.raise_from(exceptions.from_grpc_error(exc), exc)
File "<string>", line 3, in raise_from
google.api_core.exceptions.ServiceUnavailable: 503 The datastore operation timed out, or the data was temporarily unavailable.
【问题讨论】:
-
以更小的块加载数据怎么样?
-
我不是在向 Firestore 插入数据,而是在下载它。我无法控制限制数据或 where 子句。
-
这也是我所说的,以较小的块下载数据。哦,你有。签出this。
-
谢谢@AlexMamo,我会试试的。稍后我会尝试query cursors
标签: google-cloud-platform google-cloud-firestore google-cloud-datastore