Welcome to ExamTopics
ExamTopics Logo
- Expert Verified, Online, Free.
exam questions

Exam Professional Cloud Developer All Questions

View all questions & answers for the Professional Cloud Developer exam

Exam Professional Cloud Developer topic 1 question 108 discussion

Actual exam question from Google's Professional Cloud Developer
Question #: 108
Topic #: 1
[All Professional Cloud Developer Questions]

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?

  • 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.
Show Suggested Answer Hide Answer
Suggested Answer: A 🗳️

Comments

Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.
Switch to a voting comment New
p4
Highly Voted 2 years, 10 months ago
Selected: A Firestore has a “hierarchical structure”: collection contains documents, document can contain (sub)collections D does not make sense bc why do you want to link comments to the user profile instead of the article? https://stackoverflow.com/questions/48634227/limitation-to-number-of-documents-under-one-collection-in-firebase-firestore “There is no documented limit to the number of documents that can be stored in a Cloud Firestore collection. The system is designed to scale to huge data sets.”
upvoted 21 times
juancambb
2 years, 9 months ago
the subcollection has a limit of 1Mb of data, so for unknown number of comments is not valid, the answer is D
upvoted 1 times
[Removed]
2 years, 6 months ago
That's wrong, the 1MB limit it's on the document inside the subcollection (not on the subcollection itself. "Document size - Cloud Firestore is optimized for small documents and enforces a 1MB size limit on documents. If your array can expand arbitrarily, it is better to use a subcollection, which has better scaling performance." Check out also the example in the subcollections documentation, showing a rooms-messages hierarchy example. https://firebase.google.com/docs/firestore/data-model#subcollections
upvoted 6 times
...
...
...
htakami
Highly Voted 2 years, 8 months ago
Why D and not C? For my understanding, we need to keep a relation between the articles and their comments. I don't see how the user profile could come in handy... but please let me know if I misunderstood something. For me, Ans C makes more sense.
upvoted 9 times
...
thewalker
Most Recent 4 months, 1 week ago
Selected Answer: A
The best answer here is A. Store each comment in a subcollection of the article. Here's why: Scalability: Storing comments as subcollections within the article document allows you to handle an unlimited number of comments per article. Firestore scales well with large numbers of subcollections. Querying: You can easily query for comments related to a specific article using the collectionGroup() query. This allows you to retrieve all comments for an article without needing to know the specific comment IDs. Performance: Firestore's subcollection structure optimizes for reading and writing comments related to a specific article.
upvoted 1 times
thewalker
4 months, 1 week ago
Let's look at why the other options are less ideal: B. Add each comment to an array property on the article: This approach is limited by the maximum document size in Firestore (1 MB). You'll run into issues if you have a large number of comments for a single article. C. Store each comment in a document and add the comment's key to an array property on the article: This approach is less efficient for querying comments related to a specific article. You'd need to perform multiple queries to retrieve all comments. D. Store each comment in a document and add the comment's key to an array property on the user profile: This approach is not ideal for retrieving comments related to a specific article. You'd need to query the user profile for each comment, which is inefficient.
upvoted 1 times
...
...
d_ella2001
4 months, 2 weeks ago
Selected Answer: A
Firestore has a hierarchical structure
upvoted 1 times
...
alpha_canary
7 months, 2 weeks ago
Selected Answer: A
It can't be D because: Storing each comment in a document and adding the comment's key to an array property on the user profile wouldn't efficiently link comments to articles.
upvoted 1 times
...
Kadhem
11 months, 1 week ago
Selected Answer: D
Answer is D in my opinion for "display user-submitted comments" and "unknown number of comments and articles"
upvoted 1 times
...
Aeglas
1 year ago
Selected Answer: A
Answer is A
upvoted 3 times
...
Aeglas
1 year ago
Selected Answer: A
As per previous comments also appointed, there is not such a limitation on size for a Subcollection, and it does not make sense to store the relation with User profile like answer D
upvoted 3 times
...
braska
1 year ago
Selected Answer: A
Option A is the recommended approach for structuring data in Firestore to support an unknown number of comments and articles. Firestore is a NoSQL document-oriented database, and using subcollections provides a flexible and scalable way to organize related data
upvoted 2 times
...
__rajan__
1 year, 2 months ago
Selected Answer: C
I would go with C.
upvoted 1 times
...
sota_hi_there
1 year, 4 months ago
Selected Answer: A
the correct answer is A. reference: https://firebase.google.com/docs/firestore/data-model
upvoted 2 times
...
gc_exam2022
1 year, 5 months ago
Answer is D
upvoted 1 times
...
efrenpq
1 year, 6 months ago
Selected Answer: A
Firestore has a "hierarchical structure"
upvoted 1 times
...
mrvergara
1 year, 9 months ago
Selected Answer: C
It is recommended to add the comment document IDs to an array property on the corresponding article document, rather than on a user profile. This approach allows you to easily retrieve all comments for a specific article by querying the comments collection using the article ID and then filtering the results based on the IDs in the article's comments array. Storing the comment IDs in the article document also avoids the need to make multiple read operations to retrieve the comments for a given article, which can be slow and increase latency. For example, you could create an array property named "comments" in the article document and add the comment document IDs to this array every time a user submits a new comment for the article. This allows you to efficiently retrieve all comments for a given article by querying the comments collection and filtering based on the IDs in the article's "comments" array.
upvoted 1 times
...
chunker
1 year, 10 months ago
Selected Answer: A
Close to this example: https://firebase.google.com/docs/firestore/data-model#subcollections
upvoted 2 times
felipeschossler
1 year, 7 months ago
Exactly this, thanks for sharing the docs here, I change my answer because of you!
upvoted 2 times
...
...
omermahgoub
1 year, 10 months ago
Answer is A. Store each comment in a subcollection of the article, because it allows for easy scaling and querying of the comments as the data increases. With this approach, you can easily fetch the comments associated with an article by querying the subcollection of that article, instead of querying all the comments in a single collection. It also allows you to query specific comments and articles easily, since you have the reference to the specific article they are associated with.
upvoted 3 times
omermahgoub
1 year, 10 months ago
Storing each comment in a document, and adding the comment's key to an array property on the user profile (Option D) would make it more difficult to fetch all the comments associated with a specific article. Additionally, it would also make it more difficult to query the comments and articles since you would have to go through the user profile to find the comment's key and then use that to find the comment's information. The subcollection approach allows for better organization and querying of the data, making it a better choice in this scenario.
upvoted 2 times
omermahgoub
1 year, 10 months ago
C. Store each comment in a document, and add the comment's key to an array property on the article would work, but it may not be the best solution for this use case. While it would allow you to query for all the comments associated with an article by finding the document with the article and reading the array property of its key. However, this approach would make it more difficult to scale the data as the number of comments grows, because it would require you to retrieve all the comment keys in the array of the article and then perform additional queries to retrieve the actual comment information one by one. This could slow down the application as the number of comments increase, and make it more difficult to handle high-load situations.
upvoted 1 times
omermahgoub
1 year, 10 months ago
Another reason for not choosing C is that, it might also pose an issue for data consistency as comments can change over time and updating the comment document would not automatically update the array property on the article, creating inconsistencies in the data.
upvoted 1 times
...
...
...
...
TNT87
1 year, 11 months ago
https://firebase.google.com/docs/firestore/best-practices#high_read_write_and_delete_rates_to_a_narrow_document_range
upvoted 1 times
...
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

SaveCancel
Loading ...