
Answer-first summary for fast verification
Answer: Store each comment in a subcollection of the article.
Firestore is optimized for hierarchical data structures. Option A uses a subcollection under each article document to store comments, which is scalable and allows for an unbounded number of comments. Arrays (Options B, C, D) are unsuitable here because Firestore documents have a 1MB size limit, making arrays impractical for large or unknown quantities of comments. Option D also incorrectly associates comments with user profiles instead of articles. Subcollections (A) avoid these issues by enabling independent querying and scalability.
Author: LeetQuiz Editorial Team
Ultimate access to all questions.
How should you design the Firestore schema for an application that stores and displays user-submitted comments on news articles, while supporting an unknown number of comments and articles?
A
Store each comment in a subcollection of the article.
B
Add each comment to an array property on the article.
C
Store each comment in a document, and add the comment's key to an array property on the article.
D
Store each comment in a document, and add the comment's key to an array property on the user profile.
No comments yet.