PROFESSIONAL-CLOUD-DEVELOPER · Question #199
You are designing a chat room application that will host multiple rooms and retain the message history for each room. You have selected Firestore as your database. How should you represent the data…
The correct answer is C. Create a collection for the rooms. For each room, create a document that contains a collection for. Firestore's recommended pattern for one-to-many relationships is to use subcollections. The correct structure is: a top-level 'rooms' collection → one document per room → a 'messages' subcollection inside each room document → one document per message. This allows efficient…
Question
You are designing a chat room application that will host multiple rooms and retain the message history for each room. You have selected Firestore as your database. How should you represent the data in Firestore?
Exhibits
Options
- ACreate a collection for the rooms. For each room, create a document that lists the contents of the
- BCreate a collection for the rooms. For each room, create a collection that contains a document for
- CCreate a collection for the rooms. For each room, create a document that contains a collection for
- DCreate a collection for the rooms, and create a document for each room. Create a separate
How the community answered
(29 responses)- A3% (1)
- B7% (2)
- C76% (22)
- D14% (4)
Explanation
Firestore's recommended pattern for one-to-many relationships is to use subcollections. The correct structure is: a top-level 'rooms' collection → one document per room → a 'messages' subcollection inside each room document → one document per message. This allows efficient per-room queries, scales independently, and avoids hitting Firestore's 1MB per-document limit that would occur if all messages were stored as an array inside a single room document (option A). Option B creates a collection per room at the top level rather than nesting it inside a document. Option D (separate collection) loses the hierarchical relationship.
Topics
Community Discussion
No community discussion yet for this question.



