Bird
0
0

What will happen if you try to write a document with the same ID twice in Firestore on GCP?

medium📝 Predict Output Q5 of 15
GCP - Cloud Firestore and Bigtable
What will happen if you try to write a document with the same ID twice in Firestore on GCP?
AFirestore throws an error and rejects the second write
BThe second write overwrites the first document
CFirestore creates a duplicate document with a new ID
DThe first document is deleted automatically
Step-by-Step Solution
Solution:
  1. Step 1: Understand Firestore document ID uniqueness

    Document IDs are unique keys; writing with the same ID replaces the existing document.
  2. Step 2: Confirm Firestore behavior on duplicate IDs

    Firestore does not throw an error but overwrites the existing document with new data.
  3. Final Answer:

    The second write overwrites the first document -> Option B
  4. Quick Check:

    Same document ID write = overwrite [OK]
Quick Trick: Same ID write replaces document in Firestore [OK]
Common Mistakes:
  • Expecting an error on duplicate ID
  • Thinking Firestore creates duplicates
  • Assuming automatic deletion of first document

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More GCP Quizzes