nerdexam
Google

PROFESSIONAL-CLOUD-DEVELOPER · Question #125

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.

The correct answer is A. Store each comment in a subcollection of the article.. Firestore subcollections are the idiomatic way to model one-to-many relationships with an unbounded number of child documents. Storing each comment as a document in a subcollection under its parent article document (e.g., /articles/{articleId}/comments/{commentId}) allows unlimit

Implementing Cloud Databases

Question

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?

Options

  • AStore each comment in a subcollection of the article.
  • BAdd each comment to an array property on the article.
  • CStore each comment in a document, and add the comment's key to an array property on the
  • DStore each comment in a document, and add the comment's key to an array property on the user

How the community answered

(30 responses)
  • A
    73% (22)
  • B
    3% (1)
  • C
    13% (4)
  • D
    10% (3)

Explanation

Firestore subcollections are the idiomatic way to model one-to-many relationships with an unbounded number of child documents. Storing each comment as a document in a subcollection under its parent article document (e.g., /articles/{articleId}/comments/{commentId}) allows unlimited comments per article, efficient querying, and scalable reads. Option B (array on the article document) is problematic because Firestore document size is capped at 1 MB and arrays cannot be queried or paginated efficiently. Options C and D (storing comment keys in arrays) still inherit the array size and document size limitations while adding unnecessary indirection.

Topics

#Firestore#Data Modeling#NoSQL#Scalability

Community Discussion

No community discussion yet for this question.

Full PROFESSIONAL-CLOUD-DEVELOPER Practice