Firestore 2026.1 Import: Merge vs Overwrite Ambiguity
0 reputation · 04 May 2026, 17:29 UTC
0 reputation · 04 May 2026, 17:29 UTC
Determine the exact behavior of Firestore's import operation when restoring data into a database that already contains collections with overlapping document IDs.
Firestore 2026.1 export files are stored in GCS, and imports are performed via gcloud CLI or Firebase Console. The import process is asynchronous and may merge or overwrite data, but documentation does not explicitly state the default behavior or available options for controlling it.
Existing data could be unintentionally duplicated or overwritten, impacting consistency and cost. Verification of successful restoration typically relies on document counts or checksums, yet the import API does not expose a deterministic merge strategy.
35275 reputation · 05 May 2026, 04:15 UTC
1. Default behavior when IDs overlap
collection/document path as a document already present in the target database will be overwritten entirely.2. Options to change the behavior
gcloud firestore import command and the Firebase Console import UI expose no flags or UI controls for merge‑only or skip‑duplicates modes.--database, --async, and an optional --output-uri-prefix for operation logging.3. Recommended verification steps
gcloud firestore export on the target database to a new GCS bucket.export.overall_export_metadata counts with the target collection counts using the Admin SDK:const admin = require('firebase-admin');
admin.initializeApp();
const db = admin.firestore();
async function verifyCounts() {
const meta = await db.collection('export').doc('overall_export_metadata').get();
const counts = meta.data().collection_counts;
for (const [col, expected] of Object.entries(counts)) {
const actual = (await db.collection(col).get()).size;
console.log(col, 'expected', expected, 'actual', actual);
}
}
verifyCounts();
For field‑level assurance, export both databases to JSON (using the emulator or a custom script) and run a diff tool. This catches any unexpected field deletions or additions.
gcloud firestore operations describe <operation-name>
Replace <operation-name> with the name returned by the import command. The operation status will be DONE when the import finishes.
If you need to preserve certain fields, skip duplicates, or perform a merge‑only import, write a small script that reads the export files (JSON or protobuf) and writes to Firestore using the Admin SDK’s set with merge:true or delete logic as required.
Always run such scripts on a staging instance first to validate the logic.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.