Entity was of unexpected kind - firebase

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

Related

Copy Firestore Database Data to Bigquery using Cloud Shell Terminal

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

Auto Populate and Export Cloud Firestore Database {Collection} to BigQuery

I'm trying to connect the firestore collection in auto populate method to BigQuery by following github https://github.com/firebase/extensions/tree/master/firestore-bigquery-export. The successfull export shows the collection with comma separated(example: Data{id,geolocation,market,customer_name,customer_id,..} which causing difficult to visualize.
I also tried export using cloud storage bucket but its not auto update in BigQuery, whenever there is changes in particular collection from firestore.
Need help on this. thanks in advance.
You can sync data between Firestore and BigQuery by 2 ways:
Creating and triggering a Cloud Function whenever there is a change in a Firestore collection and streaming those changes into BigQuery table.
Using the "Export Collections to BigQuery" Firebase Extension.
Also please have a look into the following tutorial

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.

Can I use gcloud firestore export command for incremental exports from firestore?

The gcloud firestore export command:
gcloud firestore export gs://bucket --collection-ids=''
takes a full export of my specified collections but I want to take incremental exports of only my new documents added on a daily basis. How do I achieve that? Can the gcloud firestore export command be modified in some way to just take exports of new documents being added to my collections?
That's not currently a capability of Firestore or gcloud.
If you want to perform incremental exports, you will have to write some code or use another tool for that. The tool will need a way to know how to query for data since some point in time, and you will need data in your documents to support that. For example, you would need to have some sort of timestamp that indicates the last time the document was modified, so that it can be targeted in a query.

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

Resources