Setup guide · Cloud Firestore

Cloud Firestore in Dataki, through BigQuery

Firestore has no SQL of its own, so Dataki reads it where analytics already works: BigQuery. Google's Stream Firestore to BigQuery extension copies every change to a collection into a table as it happens, and keeps a view of each document's latest version on top.

  1. Cloud Firestore
  2. BigQuery
  3. Dataki
Setup
About 15 minutes per collection, plus a one-off import of the documents that already exist.
Cost
Needs the Blaze plan. The extension's function calls (2 million a month free) and BigQuery streaming inserts ($0.01 per 200 MiB) are billed to you.
Freshness
Seconds. Each write reaches BigQuery as it happens.
Scope
One collection per installation. Install it again for each collection you want to ask about.

01Before you start

  • A Firebase project on the Blaze plan, with Firestore set up.
  • The project linked to BigQuery: Project settingsIntegrationsBigQuery.
  • Owner, Editor or Firebase Admin on the project, and Node.js to run Google's import script.

02Set it up

4 steps, about 15 minutes

  1. 01

    Install the extension

    In the Firebase console, open Extensions, find Stream Firestore to BigQuery and choose Install. Or from a terminal:

    Terminal
    firebase ext:install firebase/firestore-bigquery-export --project=your-project
    firebase deploy --only extensions --project=your-project
    • Collection path: the collection to export, e.g. orders. A subcollection takes a wildcard, e.g. users/{uid}/orders.
    • Dataset ID defaults to firestore_export. Table ID is the prefix for everything it creates, e.g. orders.
    • Dataset location cannot be changed after installing. Pick the region the rest of your BigQuery data is in.
    • Table partitioning cannot be added later either. Set it now for a large collection.
  2. 02

    Import the documents that already exist

    The extension only sees changes made after it is running. Once it is, import the rest with Google's script, which reads Firestore with your own credentials and asks for the project, the collection, the dataset and the table prefix. Give it the same values as the extension.

    Terminal
    gcloud auth application-default login
    npx @firebaseextensions/fs-bq-import-collection
    • Run it once. A second run imports every document again.
    • Imported rows are marked IMPORT in the operation column, and any later change to a document supersedes them.
  3. 03

    Connect the dataset in Dataki

    Open app.dataki.ai/connect and, under Linked Google Cloud Projects, choose Link New Google Project. Sign in with a Google account that can manage IAM in the project holding the data, and pick that project. Dataki creates a service account named Dataki in it with two roles, BigQuery Data Viewer and BigQuery Job User: it can read tables and run queries.

    The project's datasets then appear among your sources. Pick firestore_export. Each dataset is one source in Dataki, and the free plan includes one.

    For each collection, Dataki sees orders_raw_changelog, one row per change, and orders_raw_latest, one row per document as it is now. The document is a JSON string in the data column, and Dataki reads its fields with JSON_VALUE.

  4. 04

    Optional: give the fields real columns

    For documents with many fields, Google's schema-views tool builds typed views from a short file naming each field and its type. Dataki then sees real columns, with numbers and timestamps typed, instead of one JSON string.

    orders.json
    {
      "fields": [
        { "name": "status", "type": "string" },
        { "name": "total", "type": "number" },
        { "name": "createdAt", "type": "timestamp" }
      ]
    }
    Terminal
    npx @firebaseextensions/fs-bq-schema-views \
      --non-interactive \
      --project=your-project \
      --big-query-project=your-project \
      --dataset=firestore_export \
      --table-name-prefix=orders \
      --schema-files=./orders.json
    • It creates orders_schema_orders_latest and orders_schema_orders_changelog next to the raw tables.
    • An array field is unnested into _member and _index columns, one row per element, so count documents with COUNT(DISTINCT document_id).

03Ask it

Your first questions

Two questions against the raw tables, and one against the typed view. Replace orders with your table prefix.

How many orders are in each status right now?

BigQuery · firestore_export
SELECT
  JSON_VALUE(data, '$.status') AS status,
  COUNT(*) AS orders
FROM `your-project.firestore_export.orders_raw_latest`
GROUP BY status
ORDER BY orders DESC

How many new orders came in each week?

Counted from the changelog, where each new document is a CREATE. Documents brought in by the import script are IMPORT rows with no creation time of their own, so this starts on the day the extension was installed.

BigQuery · firestore_export
SELECT
  DATE_TRUNC(DATE(timestamp), WEEK) AS week,
  COUNT(*) AS new_orders
FROM `your-project.firestore_export.orders_raw_changelog`
WHERE operation = 'CREATE'
GROUP BY week
ORDER BY week

What were orders worth each week, by when they were created?

Needs the typed view from the optional step, which turns createdAt into a timestamp and total into a number.

BigQuery · firestore_export
SELECT
  DATE_TRUNC(DATE(createdAt), WEEK) AS week,
  COUNT(*) AS orders,
  ROUND(SUM(total), 2) AS revenue
FROM `your-project.firestore_export.orders_schema_orders_latest`
GROUP BY week
ORDER BY week

04Worth knowing

What you will run into

Firebase is retiring Extensions
Google has deprecated the Firebase Extensions service and will shut it down on 31 March 2027. An installed extension keeps running after that, but can no longer be updated, reconfigured or uninstalled from the console or the CLI. Google has said it will publish a migration to self-managed functions; the pre-release version writes the same _raw_changelog and _raw_latest tables, so what you build in Dataki should carry over.
Deleted documents
The _raw_latest view leaves deleted documents out. The changelog keeps them, as DELETE rows.
Queries are billed to your project
Dataki runs each query in the project that holds the data, and Google bills that project for it. The first 1 TiB of queries each month is free. A question that names a period lets the query read only those days, which is what keeps it small.
Your organization may block the key Dataki needs
Linking a project creates a key for the Dataki service account. Google Cloud organizations created on or after 3 May 2024 block key creation by default, through the iam.disableServiceAccountKeyCreation policy. If linking fails there, an organization admin can lift that policy for this one project. Projects outside an organization are not affected.

05Other routes

If this route does not suit you

A snapshot instead of a stream

If a periodic copy is enough, export the collection and load it into BigQuery, with nothing installed. Maps and arrays become typed columns. Each load replaces the table, one collection at a time, and the dataset must be in the same location as the bucket.

Terminal
gcloud firestore export gs://your-bucket --collection-ids=orders
bq --location=US load --source_format=DATASTORE_BACKUP --replace \
  firestore_snapshot.orders \
  gs://your-bucket/<export-folder>/all_namespaces/kind_orders/all_namespaces_kind_orders.export_metadata

Free while we are in beta

Connect Cloud Firestore. Ask it something.

Once the data is where Dataki can read it, the first answer is a question away, and anything worth keeping becomes a dashboard with a link that stays live.

One data source
Free tier. Connect a second on any paid plan.
Read-only
Every query runs read-only. Dataki cannot change your data.
No card
There is nothing to cancel if you stop.