Google Cloud Professional Cloud Developer — Question 124
You are developing an application that will allow users to read and post comments on news articles. You want to configure your application to store and display user-submitted comments using Firestore. How should you design the schema to support an unknown number of comments and articles?
Answer options
- 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.
Correct answer: A
Explanation
The correct approach is to store each comment in a subcollection of the article, which allows for an unlimited number of comments without altering the article document structure. Storing comments in an array on the article could lead to performance issues as the number of comments grows, while using an array property for user profiles does not associate comments directly with the articles they belong to.