我在谷歌云计算公司的FireStore集合data
。这个系列拥有200K的文件。我想每个文档导出为一行的文件。
我创建了为50,000列做工精细的脚本。此后它与下面的异常崩溃。我怎样才能获得的所有文件?
我看到一些所谓的偏移,但不知道它可以帮助我的情况。
代码片段:
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客户有get()
20秒超时。尽量将工作或尝试获取所有的文档引用,然后迭代。
docs = [snapshot.reference for snapshot in col.get()]
for doc in docs:
...
还有另一种方法,我认为会的工作使用gcloud指令行工具,这将要求您使用的水桶存储和BigQuery的,都是很容易走了。
gcloud beta firestore export gs://[BUCKET_NAME] --collection-ids=[COLLECTION_ID_1],[COLLECTION_ID_2]
你的整个集合将被导出到一个GCS桶,数据格式是一样的云存储古都可读通过大量查询等等..
select * from [TABLE_NAME]
表形式的BigQuery,然后的BigQuery有一个选项,以下载查询结果为CSV我创建了为50,000列做工精细的脚本。
该限制恰恰是火力地堡的number of documents that you can read on a project on the free/Spark plan。如果你的项目是免费的计划,你需要将它升级到阅读每天的文档。