Design Firestore collections to migrate user profiles and posts from MySQL. How should you structure collections and subcollections?
Choose an answer
Tap an option to check your answer.
Correct answer: Create one root collection for user profiles, and create one subcollection for each user's posts..
Why this is the answer
This approach leverages Firestore's hierarchical data model effectively. A root collection for users allows for easy querying and management of individual user profiles. Creating a subcollection named posts under each user document (e.g., users/{userId}/posts/{postId}) provides a natural and scalable way to store posts associated with a specific user. This structure allows for efficient retrieval of all posts by a particular user without needing to query a large, single posts collection and filter by user ID. Storing posts as a nested list field in the user profile document (option 3) is generally discouraged for large or frequently updated lists, as Firestore documents have a size limit and updates to a single document can become contention points. Creating one root collection for user posts (option 1 and 4) would require querying the entire collection and filtering by user ID, which is less efficient than using subcollections when retrieving user-specific data.
Pass your exam — without the endless answer hunt
Get every verified question and explanation for this exam in one place, and save hours of prep. 1,000+ certifications · 20+ languages · free to start.
Pass your exam faster → No card needed