Copy Firestore Database Data to Bigquery using Cloud Shell Terminal - firebase

Does anyone know how I can manually copy/transfer data from Firestore database to Bigquery using Cloud Shell Terminal?
I did this in the past but I'm unable to find the documentation/video that I used. I find a lot that states that once Bigquery is connected to Firebase, it should be automatic but mine is not.
When I ran code in the Cloud Shell Terminal to pull data from Firebase the collection was copied as a table into a Bigquery dataset. Two tables were created and "raw_latest" and "raw_changelog" were created.
I'm not sure how to transfer another collection now.
I specifically need to transfer data from a subcollection in the Firestore database.

You can now export data from Cloud Firestore to BigQuery with a
Firebase Extension. To import all the previous data you will need
first to install the extension because all the writes while doing
the export first without installing the extension will be lost.
See: https://firebase.google.com/products/extensions/firestore-bigquery-export
Firestore allows import / export data to BigQuery using a GCS
bucket. The data is exported to a Cloud Storage bucket and from
there it can be imported into Big Query.
The gcloud commands for the same are :
export data :
gcloud beta firestore export --collection-ids=users gs://my bucket/users
load backup into bq :
bq load --source_format=DATASTORE_BACKUP mydataset.users gs://gs://mybucket/users/all_namespaces/kind_users/all_namespaces_kind_users.export_metadata
Here are some links that might be helpful:
https://firebase.google.com/docs/firestore/manage-data/export-import
https://cloud.google.com/bigquery/docs/loading-data-cloud-datastore
https://github.com/firebase/extensions/blob/master/firestore-bigquery-export/guides/IMPORT_EXISTING_DOCUMENTS.md

Related

How long does it take for data in firebase collections to start exporting to BigQuery?

I have installed a firebase extension "collections to bigquery" to export the data in my firebase collection to the BigQuery table. I have installed the extension an hour ago and I can still not see any data in the BigQuery. I am new to FireBase so can anyone tell me how long does it usually take until data finally starts showing up in BigQuery?
Thanks!
The Firestore BigQuery extension will automatically sync future writes to a collection to BigQuery - if your database isn't actively being written to, it won't do anything just by installing it.
To bring existing documents into the BigQuery table, see this guide that runs through how to run the import script.

In Google Cloud Firestore, how can I export storage also at the same time as collections?

In Google Cloud Firestore we store collection data and storage data (jpeg files). Is it possible to export them together and import them together? We export like this:
gcloud beta firestore export gs://backups-projectname
...and import like this into another project:
gcloud beta firestore import gs://backups-projectname/2019-06-28T18:18:37_6038/
It does, partially, work: the collection data shows up in the new location. But the storage data doesn't. Is the storage not included in the export? Can it be included with a flag? Or is there a separate command?
Note: I'm not talking about copying the files independently gsutil cp -r I can already get the files into the Firestore Storage with that command, e.g.:
gsutil cp -r gs://projectname.appspot.com gs://projectname-86abf.appspot.com
I want the Firestore database and file storage to be exported as a single large object and imported from that same large object. If that's not possible, what's the recommended way to accomplish this?

Entity was of unexpected kind

1)Firstly i did firestore export through console
2) Secondly when i try load data from Cloud Firestore exports
By steps given in this link - https://cloud.google.com/bigquery/docs/loading-data-cloud-datastore
3) I get the error saying 'Entity was of unexpected **** '
Here '****' represents collection name in firestore
There are some limitations when loading Firestore exports to BigQuery, these two may be related to the error you are observing:
For a Cloud Firestore export to load correctly, documents in the export data must share a consistent schema.
Your export command must specify a collection-ids filter. Data exported without specifying a collection ID filter cannot be loaded into BigQuery.
I also noticed you are following the procedure to load Datastore Exports to BigQuery. You may want to follow Firestore Exports to BigQuery instead, although they are very similar.
I can confirm that exporting a single collection solved this exact issue for me.
For whatever reason, firestore refused to allow me to export a specific collection through the console UI, which made it impossible for me to get the data into bigquery. The workaround is to open the cloud shell terminal while on the firestore gcp console page and inserting the following command
$ gcloud firestore export gs://[BUCKET_NAME] --collection-ids=[COLLECTION_ID_1],[COLLECTION_ID_2]
More detail on this can be found at https://firebase.google.com/docs/firestore/manage-data/export-import#gcloud_1

importing data from firestore into bigQuery

I have upgraded my account to blaze which is one of the prerequisite. I have tried to followed the FAQ Link BigQuery to Firebase. still not able to see any of the data from firestore or firebase-realtimeDatabase into bigQuery.
I see option in bigQuery to create Dataset. however after creating dataset it allows me to upload data from [file], [cloud storage], [bigQuery],[google Drive] . but not firestore database.
Plesae help.
Firestore now allows to import / export data. The data is exported to a Cloud Storage bucket and from there it can be imported into Big Query. Here are some links that might be helpful:
https://firebase.google.com/docs/firestore/manage-data/export-import
https://cloud.google.com/bigquery/docs/loading-data-cloud-datastore (Firestore uses the same format as Datastore for imports / exports)
** Edit:
Docs for BigQuery imports from Firestore are now available https://cloud.google.com/bigquery/docs/loading-data-cloud-firestore
In case anyone need it. I ended up automating scripts because current export data option only allows stream data and preserve for 30 days.
export data
gcloud beta firestore export --collection-ids=users gs://mybucket/users
load backup into bq
bq load --source_format=DATASTORE_BACKUP mydataset.users gs://gs://mybucket/users/all_namespaces/kind_users/all_namespaces_kind_users.export_metadata
You can now export data from Cloud Firestore to BigQuery with a Firebase Extension. See: https://firebase.google.com/products/extensions/firestore-bigquery-export
Also see David's answer on how to import/export data.
Outdated answer below:
There is no built-in support to import data from the Firebase Realtime Database or Cloud Firestore into BigQuery.
For now, if you want to import data, you'll have to write code to do so.
You should use the BigQuery export extension built-in in Firebase
See details: https://firebase.google.com/products/extensions/firestore-bigquery-export
Now, this extension will be importing to your BigQuery table new created/updated/deleted documents inside a collection, your current old data before the new one is added will not be placed inside this table.
To import all the previous data you will need first to install the extension because all the writes while doing the export first without installing the extension will be lost.
After you install the extension, just use gcloud to export all the current dataset
https://github.com/firebase/extensions/blob/master/firestore-bigquery-export/guides/IMPORT_EXISTING_DOCUMENTS.md
I made an NPM package that lets you create a BigQuery dataset and tables with autogenerated schemas based on your Firestore data, and then copy and convert chosen Firestore collections.
https://www.npmjs.com/package/firestore-to-bigquery-export
There is now also an extension that does it https://github.com/firebase/extensions/tree/master/firestore-bigquery-export

gcloud command to save datastore kind to google storage

Looking for gcloud command to save the google cloud datastore entities to google cloud storage.Right now I'm manually doing all the operations would like to see if this can be done through shell commands as well.
There's a command to export named kinds to GCS:
gcloud beta datastore export --kinds="KIND1, KIND2" --namespaces="NAMESPACE1, NAMESPACE2" gs://${BUCKET}
Typically, you would run:
gcloud beta datastore export --kinds="foo" --namespaces="(default)" gs://my-gcs-bucket/datastore_export/2017-11-09_12_00
The documentation can be found here:
https://cloud.google.com/datastore/docs/export-import-entities
And then the exported data can then be loaded into BigQuery.
If you don't want to load the data into BigQuery, the format isn't documented, but here are some references for how to read the entities from the exported LevelDB files:
http://varunpant.com/posts/read-gae-admin-backups-fromleveldb-format-and-export-gae-entities-using-bulkloader
http://gbayer.com/big-data/app-engine-datastore-how-to-efficiently-export-your-data/

Resources