Bird
0
0

You want to model a Firestore document for a blog post with multiple comments, each comment having an author and text. Which is the best approach?

hard📝 Application Q8 of 15
GCP - Cloud Firestore and Bigtable
You want to model a Firestore document for a blog post with multiple comments, each comment having an author and text. Which is the best approach?
AUse a nested array of maps inside the document for comments
BUse a single map field with keys as comment IDs and values as text
CStore comments as separate documents in a subcollection
DCombine all comments into a single string field
Step-by-Step Solution
Solution:
  1. Step 1: Consider data structure for multiple comments

    Comments can grow large and need individual access, so storing them separately is better.
  2. Step 2: Evaluate options for scalability and querying

    Using a subcollection for comments allows efficient queries and updates per comment.
  3. Final Answer:

    Store comments as separate documents in a subcollection -> Option C
  4. Quick Check:

    Subcollections best for multiple related documents [OK]
Quick Trick: Use subcollections for many related items like comments [OK]
Common Mistakes:
  • Using arrays for large or growing data
  • Storing all comments in one string
  • Using maps with dynamic keys

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More GCP Quizzes