如何从谷歌云公司的FireStore下载大量的文件?

问题描述 投票:0回答:3

我在谷歌云计算公司的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.
google-cloud-platform google-cloud-firestore google-cloud-datastore
3个回答
1
投票

云蟒的FireStore客户有get() 20秒超时。尽量将工作或尝试获取所有的文档引用,然后迭代。

docs = [snapshot.reference for snapshot in col.get()]
for doc in docs:
        ...

Github issue regarding timeout


1
投票

还有另一种方法,我认为会的工作使用gcloud指令行工具,这将要求您使用的水桶存储和BigQuery的,都是很容易走了。

  1. 导出使用终端的gcloud firetore export function集合:
gcloud beta firestore export gs://[BUCKET_NAME] --collection-ids=[COLLECTION_ID_1],[COLLECTION_ID_2]

你的整个集合将被导出到一个GCS桶,数据格式是一样的云存储古都可读通过大量查询等等..

  1. 负荷GCS Bucket to Bigquery数据,导出收藏的FireStore将生活中的BigQuery表格
  2. 查询的东西,如select * from [TABLE_NAME]表形式的BigQuery,然后的BigQuery有一个选项,以下载查询结果为CSV

0
投票

我创建了为50,000列做工精细的脚本。

该限制恰恰是火力地堡的number of documents that you can read on a project on the free/Spark plan。如果你的项目是免费的计划,你需要将它升级到阅读每天的文档。

© www.soinside.com 2019 - 2024. All rights reserved.