
Answer-first summary for fast verification
Answer: Create a collection for the rooms. For each room, create a collection that contains a document for each message
In Firestore, each chat room should be a document in a 'rooms' collection. To handle potentially large message histories without hitting document size limits, messages should be stored in a subcollection under each room document. This allows each message to be an individual document within the subcollection, ensuring scalability. Option B correctly describes this structure: creating a collection for rooms, with each room having a subcollection (messages) containing individual message documents. Option C's wording is misleading, as documents cannot 'contain' collections directly; subcollections exist under a document's path, not as part of its data.
Author: LeetQuiz Editorial Team
Ultimate access to all questions.
How should you structure the data in Firestore when designing a chat room application that hosts multiple rooms and retains message history for each room?
A
Create a collection for the rooms. For each room, create a document that lists the contents of the messages
B
Create a collection for the rooms. For each room, create a collection that contains a document for each message
C
Create a collection for the rooms. For each room, create a document that contains a collection for documents, each of which contains a message.
D
Create a collection for the rooms, and create a document for each room. Create a separate collection for messages, with one document per message. Each room’s document contains a list of references to the messages.
No comments yet.