Skip to main content
RapidDev - Software Development Agency
firebase-tutorial

How to Export Firestore Data to BigQuery

To export Firestore data to BigQuery, install the Firebase Extension 'Stream Firestore to BigQuery' from the Firebase Console. The extension creates a BigQuery dataset and streams all document changes in real time. For historical data, run the included backfill script to import existing documents. You can then query your Firestore data with SQL in BigQuery for analytics, reporting, and complex aggregations that Firestore cannot handle natively.

What you'll learn

  • How to install and configure the Firestore BigQuery Export extension
  • How to backfill existing Firestore data into BigQuery
  • How to query exported Firestore data with SQL in BigQuery
  • How to set up scheduled exports for batch analytics
Book a free consultation
4.9Clutch rating
600+Happy partners
17+Countries served
190+Team members
Intermediate6 min read20-30 minFirebase Blaze plan (required for Extensions), BigQuery (Google Cloud)March 2026RapidDev Engineering Team
TL;DR

To export Firestore data to BigQuery, install the Firebase Extension 'Stream Firestore to BigQuery' from the Firebase Console. The extension creates a BigQuery dataset and streams all document changes in real time. For historical data, run the included backfill script to import existing documents. You can then query your Firestore data with SQL in BigQuery for analytics, reporting, and complex aggregations that Firestore cannot handle natively.

Streaming Firestore Data to BigQuery for Analytics

Firestore excels at real-time reads and writes but lacks complex query capabilities like JOINs, aggregations across collections, and ad-hoc SQL queries. BigQuery fills this gap by providing a serverless data warehouse where you can run SQL queries against your Firestore data. This tutorial covers real-time streaming via the official Firebase Extension and batch export for historical analysis.

Prerequisites

  • A Firebase project on the Blaze (pay-as-you-go) plan
  • A Firestore database with existing data or an active collection
  • A Google Cloud project with BigQuery API enabled
  • The Firebase CLI installed (v13 or later) for backfill operations

Step-by-step guide

1

Install the Stream Firestore to BigQuery extension

Go to the Firebase Console, click Extensions in the left sidebar, and search for 'Stream Firestore to BigQuery'. Click Install and select your Firebase project. The installation wizard asks you to configure the collection path to monitor (e.g., 'orders'), the BigQuery dataset ID (it creates one if it does not exist), and the table ID for the changelog. The extension deploys a Cloud Function that triggers on every Firestore document write.

Expected result: The extension appears in your Firebase Console under Extensions with a status of 'Installed'.

2

Configure the extension settings

During installation, set the Collection path to the Firestore collection you want to export (e.g., 'orders'). Set the BigQuery Dataset ID (e.g., 'firestore_export'). Choose whether to use wildcard collection monitoring to include subcollections. Enable 'Use new query syntax' for the latest BigQuery views. The extension creates a changelog table that records every CREATE, UPDATE, and DELETE operation with timestamps.

typescript
1// Extension configuration (set during installation):
2// Collection path: orders
3// Dataset ID: firestore_export
4// Table ID: orders_raw_changelog
5// Wildcard: No (or Yes for subcollections)
6// Partition: timestamp (recommended for cost optimization)

Expected result: The extension configuration is saved and a BigQuery dataset with changelog table is created.

3

Backfill existing Firestore data

The extension only captures changes made after installation. To import existing documents, run the backfill script included with the extension. This script reads all documents in the configured collection and writes them to BigQuery as initial records. For large collections, the backfill can take several minutes. Run it from your terminal with npx.

typescript
1npx @firebaseextensions/fs-bq-import-collection \
2 --non-interactive \
3 --project your-project-id \
4 --source-collection-path orders \
5 --dataset firestore_export \
6 --table-name-prefix orders

Expected result: All existing documents in the collection are imported into BigQuery. The terminal shows a count of documents processed.

4

Generate the latest snapshot view in BigQuery

The changelog table contains every version of every document. To get the current state, the extension provides a script that creates a BigQuery view showing only the latest version of each document. This view deduplicates the changelog and gives you a clean snapshot table for analytics queries.

typescript
1npx @firebaseextensions/fs-bq-schema-views \
2 --non-interactive \
3 --project your-project-id \
4 --dataset firestore_export \
5 --table-name-prefix orders

Expected result: A BigQuery view named orders_schema_orders_schema_latest is created with the current state of all documents.

5

Query your Firestore data with SQL in BigQuery

Open the BigQuery Console and run SQL queries against your exported data. You can now perform JOINs, aggregations, date-range filtering, and complex analytics that are impossible in Firestore. The changelog table records the full history of changes, while the latest view shows current document states.

typescript
1-- Total revenue by month from orders collection
2SELECT
3 FORMAT_TIMESTAMP('%Y-%m', TIMESTAMP(data.createdAt)) AS month,
4 SUM(CAST(data.total AS FLOAT64)) AS revenue,
5 COUNT(*) AS order_count
6FROM `your-project.firestore_export.orders_schema_orders_schema_latest`
7WHERE data.status = 'completed'
8GROUP BY month
9ORDER BY month DESC;
10
11-- Find users with more than 10 orders
12SELECT
13 data.userId,
14 COUNT(*) AS order_count,
15 SUM(CAST(data.total AS FLOAT64)) AS total_spent
16FROM `your-project.firestore_export.orders_schema_orders_schema_latest`
17GROUP BY data.userId
18HAVING order_count > 10
19ORDER BY total_spent DESC;

Expected result: Query results show aggregated analytics data from your Firestore collection.

Complete working example

bigquery-analytics.sql
1-- Revenue by month from the latest snapshot view
2SELECT
3 FORMAT_TIMESTAMP('%Y-%m', TIMESTAMP(data.createdAt)) AS month,
4 SUM(CAST(data.total AS FLOAT64)) AS revenue,
5 COUNT(*) AS order_count
6FROM `your-project.firestore_export.orders_schema_orders_schema_latest`
7WHERE data.status = 'completed'
8GROUP BY month
9ORDER BY month DESC;
10
11-- Top customers by total spend
12SELECT
13 data.userId,
14 data.email,
15 COUNT(*) AS order_count,
16 SUM(CAST(data.total AS FLOAT64)) AS total_spent,
17 MIN(TIMESTAMP(data.createdAt)) AS first_order,
18 MAX(TIMESTAMP(data.createdAt)) AS last_order
19FROM `your-project.firestore_export.orders_schema_orders_schema_latest`
20GROUP BY data.userId, data.email
21ORDER BY total_spent DESC
22LIMIT 100;
23
24-- Daily active users from changelog (tracks all changes)
25SELECT
26 DATE(timestamp) AS day,
27 COUNT(DISTINCT JSON_VALUE(data, '$.userId')) AS active_users
28FROM `your-project.firestore_export.orders_raw_changelog`
29WHERE operation = 'CREATE'
30GROUP BY day
31ORDER BY day DESC
32LIMIT 30;
33
34-- Document change history for auditing
35SELECT
36 document_id,
37 operation,
38 timestamp,
39 data
40FROM `your-project.firestore_export.orders_raw_changelog`
41WHERE document_id = 'specific-order-id'
42ORDER BY timestamp DESC;

Common mistakes when exporting Firestore Data to BigQuery

Why it's a problem: Forgetting to run the backfill script, leaving existing documents missing from BigQuery

How to avoid: The extension only streams changes made after installation. Always run the fs-bq-import-collection backfill script to import existing documents.

Why it's a problem: Querying the changelog table instead of the latest view, getting duplicate document versions

How to avoid: Use the schema views script to generate a latest-snapshot view. Query this view for current document states. Use the changelog table only for historical analysis.

Why it's a problem: Not enabling timestamp partitioning, resulting in expensive full-table scans

How to avoid: Enable partitioning during extension setup. When querying, always include a timestamp filter to limit the data scanned.

Why it's a problem: Installing the extension on the Spark plan and getting a billing error

How to avoid: The Firestore BigQuery Export extension requires the Blaze plan because it deploys Cloud Functions. Upgrade to Blaze before installing.

Best practices

  • Enable timestamp partitioning on BigQuery tables to reduce query costs significantly
  • Run the backfill script immediately after installing the extension to include historical data
  • Regenerate schema views whenever your Firestore document structure changes
  • Use the changelog table for audit trails and the latest view for current-state analytics
  • Set up scheduled queries in BigQuery for recurring reports instead of running them manually
  • Monitor the Cloud Function logs in the Firebase Console to catch any streaming errors
  • Install separate extension instances for each collection you want to export

Still stuck?

Copy one of these prompts to get a personalized, step-by-step explanation.

ChatGPT Prompt

I want to export my Firestore 'orders' collection to BigQuery for analytics. Show me how to install the Firebase Extension, backfill existing data, and write SQL queries to calculate monthly revenue and top customers.

Firebase Prompt

Set up the Stream Firestore to BigQuery extension for my 'orders' collection. Configure timestamp partitioning. Show me the backfill command and SQL queries for revenue by month, top customers, and daily active users.

Frequently asked questions

Does the BigQuery export extension cost money?

The extension itself is free to install, but it uses Cloud Functions (billed per invocation) and BigQuery (billed per storage and query). For a moderate-traffic app with 10,000 writes per day, expect costs under $5 per month.

Can I export multiple collections to BigQuery?

Yes, install the extension once per collection. Each instance monitors one collection path and creates its own BigQuery table. You can install as many instances as you need.

Is the export real-time or batched?

The extension streams changes in near real-time via Cloud Functions triggered on Firestore writes. There is a slight delay of a few seconds. For batch exports of existing data, use the backfill script.

What happens if the Cloud Function fails to write to BigQuery?

The extension includes retry logic for transient failures. If a write consistently fails, the error appears in Cloud Function logs. Data may be temporarily missing from BigQuery but Firestore data is never affected.

Can I export subcollections?

Yes, enable the wildcard option during extension configuration. This monitors all documents at the specified path and any subcollections below it.

Can RapidDev help set up a Firestore-to-BigQuery analytics pipeline?

Yes, RapidDev's engineering team can configure the BigQuery export extension, design analytics queries, and build dashboards on top of your Firestore data.

RapidDev

Talk to an Expert

Our team has built 600+ apps. Get personalized help with your project.

Book a free consultation

Need help with your project?

Our experts have built 600+ apps and can accelerate your development. Book a free consultation — no strings attached.

Book a free consultation

We put the rapid in RapidDev

Need a dedicated strategic tech and growth partner? Discover what RapidDev can do for your business! Book a call with our team to schedule a free, no-obligation consultation. We'll discuss your project and provide a custom quote at no cost.