How do you migrate from Firebase Realtime Database to Firestore?

Answer

Migration strategy from Realtime Database (RTDB) to Firestore: (1) Data export — export RTDB data as JSON from the Firebase console; (2) Data model redesign — RTDB uses a flat JSON tree; Firestore uses collections/documents. Don't just convert 1:1 — redesign for Firestore's query model. RTDB arrays become subcollections or map fields; deeply nested JSON becomes separate collections; (3) Import script — write a Node.js script using Admin SDK to read exported JSON and write to Firestore in batches (500 docs per batch): const batch = admin.firestore().batch(); users.forEach(user => { batch.set(db.collection("users").doc(user.id), transform(user)) }); await batch.commit(); (4) Dual-write period — write to both RTDB and Firestore simultaneously during migration; reads come from Firestore; validate consistency; (5) Security rules migration — RTDB rules have different syntax than Firestore rules; rewrite from scratch following Firestore patterns; (6) SDK changes — update all client code to use Firestore SDK (different API surface); (7) Cutover — switch reads to Firestore-only after validation; disable RTDB writes; (8) Cost modeling — Firestore pricing is per-operation, not bandwidth; model the cost impact before migrating.