Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Dataflow MongoDB to BigQuery template: How to overwrite BigQuery tables?

Hey, I have a question about Dataflow MongoDB to BigQuery template. I can't understand how can I overwrite the table in BigQuery with every new upload from MongoDB? Currently Dataflow template works only in the Append mode and I can't find anything useful in the template settings to change the mode from Append to Overwrite. Please advise how to troubleshoot this.

1 1 190
1 REPLY 1

The  Dataflow MongoDB to BigQuery template is designed for appending data and doesn't natively support overwriting. To simulate an overwrite functionality, you can implement a workaround:

  • Run Dataflow Job: Execute the Dataflow job to load MongoDB data into a staging table in BigQuery.
  • Overwrite Destination Table: After the Dataflow job completes, you need a mechanism to replace the contents of the destination table with the newly loaded data.

 

Option 1: Replace Table:

 
CREATE OR REPLACE TABLE `project.dataset.destination_table` AS
SELECT * FROM `project.dataset.staging_table`;  -- (Optional staging table)

Option 2: Truncate and Insert:

 
TRUNCATE TABLE `project.dataset.destination_table`; 
INSERT INTO `project.dataset.destination_table`
SELECT * FROM `project.dataset.staging_table`;  -- (Optional staging table)