Reputation: 197
I have a conversations node which contains straightforward subnodes such as displayMessage and conversationName, but also larger subnodes such as messages which hold info on all messages sent within the conversation. Is there a way to observe data only from specific subnodes, since I want to fetch data on the imageUrl, name, and displayMessage but I don't want it to fetch data on all the messages since with a giant list of messages it would unnecessarily use up a lot of data.
Upvotes: 0
Views: 41
Reputation: 599001
While the Firebase Database allows you to mix all kinds of content in a single branch, it is typically an anti-pattern if you have multiple entity types in a single branch.
In your example JSON, I see three main data types:
Typically you should model those in three separate top-level lists, where each has the same child keys (the conversation IDs) and then the specific data of that type for each conversation.
conversations
conversation1: { conversationName: "", displayMessage: "",lastMessageTime: 1532968664.3149939 }
conversation2: { conversationName: "", displayMessage: "" }
members
conversation1: { ... }
conversation2: { ... }
messages
conversation1: {
"-Llg...": { ... },
"DBC972...": { ... }
}
conversation2: { ... }
Upvotes: 1