Google Cloud Professional Cloud Developer Practice Test

Image Description

Question: 1 / 400

What is the best way to store user-submitted comments in Firestore for an application with an unknown number of comments and articles?

Store each comment in a subcollection of the article

Storing each comment in a subcollection of the article is the most effective method for managing user-submitted comments in Firestore, especially when dealing with an unpredictable number of comments and articles. This approach leverages Firestore's hierarchical data model effectively.

By creating a subcollection for comments under each article, you maintain a clear relationship between articles and their corresponding comments, which simplifies data retrieval and enhances query performance. This structure allows for efficient querying where you can easily fetch all comments related to a specific article without sifting through unrelated data. Each comment can exist as a separate document within the subcollection, making it easy to manage, update, and delete comments as needed.

Furthermore, Firestore's limitations on the size of documents and the number of properties an array can hold make the first choice preferable in the long run. If comments were stored in an array property directly on an article, you risk hitting document size limits as the number of comments increases. Storing comments as separate documents in a subcollection allows you to bypass these constraints and efficiently handle growth in data volume.

Additionally, maintaining each comment in its own document enhances the ability to scale and manage the application as more users submit comments. It also allows you to implement features like real-time updates,

Get further explanation with Examzify DeepDiveBeta

Add each comment to an array property on the article

Store each comment in a document, and add the comment's key to an array property on the user profile

Store each comment in a document, and add the comment's key to an array property on the article

Next Question

Report this question

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy