I have a collection data
in Google cloud Firestore. This collection has over 200K documents. I want to export each document as a line to a file.
I created a script which is working fine for 50K rows. After that its crashing with following exception. How can I get all documents?
I saw something called offset, but not sure its helps in my situation.
Code Snippet:
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')
Exception:
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.