Learn how to export Firestore data to BigQuery easily. Our guide shows you how to link Firebase, deploy Cloud Functions, and set up scheduled exports.

Book a call with an Expert
Starting a new venture? Need to upgrade your web app? RapidDev builds application with your growth in mind.
Step 1: Set Up Firebase and BigQuery
Make sure you have a Firebase project and a Google Cloud project. Ensure that both Firestore and BigQuery services are enabled. You need Firestore to have data to export and BigQuery to be active for data import.
Step 2: Link Firebase to your Google Cloud Project
Step 3: Enable Billing and BigQuery API
Step 4: Set Up Firestore Export Function
You need to write a Cloud Function to trigger data export from Firestore to Cloud Storage. Later, you will load this data into BigQuery.
const functions = require('firebase-functions');
const admin = require('firebase-admin');
const { BigQuery } = require('@google-cloud/bigquery');
const { Firestore } = require('@google-cloud/firestore');
const firestore = new Firestore();
admin.initializeApp();
exports.exportFirestoreToBigQuery = functions.pubsub
.schedule('every 24 hours')
.onRun(async (context) => {
const datasetId = 'your_dataset_id';
const tableId = 'your_table_id';
const collectionName = 'your_collection_name';
const bigquery = new BigQuery();
const query = firestore.collection(collectionName);
const snapshot = await query.get();
const rows = [];
snapshot.forEach(doc => {
rows.push(doc.data());
});
await bigquery
.dataset(datasetId)
.table(tableId)
.insert(rows);
console.log(`Exported ${rows.length} rows to BigQuery`);
return null;
});
Step 5: Deploy Your Cloud Function
Make sure your Firebase environment is set up to deploy functions.
firebase deploy --only functions:exportFirestoreToBigQuery
Step 6: Verify Data in BigQuery
Step 7: Set Up Scheduled Exports (Optional)
If you need to regularly update BigQuery with new Firestore data, consider setting up a Cloud Scheduler. This has been partially accomplished with the use of the functions.pubsub.schedule that already schedules the function.
Conclusion
This step-by-step guide helps you export Firestore data to BigQuery. Ensure all service accounts, permissions, and billing configurations are correctly set to avoid interruptions in data transfers.
When it comes to serving you, we sweat the little things. That’s why our work makes a big impact.