
Answer-first summary for fast verification
Answer: Create one root collection for user profiles, and create one subcollection for each user's posts.
Firestore is optimized for hierarchical data structures. User profiles are standalone entities, making a root collection appropriate. Each user's posts are a one-to-many relationship best handled via subcollections under each user profile document. This avoids document size limits (unlike nested lists in Option C) and ensures efficient querying. Option A's root collection for posts would require filtering by user ID, which is less efficient. Option D incorrectly models user profiles as subcollections of posts, which is illogical. Thus, Option B is correct.
Author: LeetQuiz Editorial Team
Ultimate access to all questions.
As a developer migrating an on-premises MySQL database for a social media platform to Google Cloud's Firestore, how would you design the Firestore collections to store user profiles and posts effectively?
A
Create one root collection for user profiles, and create one root collection for user posts.
B
Create one root collection for user profiles, and create one subcollection for each user's posts.
C
Create one root collection for user profiles, and store each user's post as a nested list in the user profile document.
D
Create one root collection for user posts, and create one subcollection for each user's profile.
No comments yet.