Sample data for snapshot from Firebase Realtime

145 views
Skip to first unread message

Igor Lebedev

unread,
Jan 8, 2023, 4:04:23 PM1/8/23
to Firebase Google Group
Hi all! 

I doubted where to put my question - probably more appropriate in stackoverflow. But still, the question is not about the code, but about the very possibility of selective data for snapshot in order to receive a node not with all child nodes, but selectively. Is it possible?
I read about data structuring, which said that getting a node is only possible in its entirety ( https://firebase.google.com/docs/database/web/structure-data#best_practices_for_data_structure ) , but suddenly I misunderstood something.

Very thanks!

Frank van Puffelen

unread,
Jan 8, 2023, 4:10:20 PM1/8/23
to Firebase Google Group
The Firebase Realtime Database always returns complete nodes. You can't get a subset of the properties if a number of nodes, like only the name property from a list of user nodes.

The only way you can get a subset of child nodes, is if you get a slice of the data with the sort and filter (i.e. query) operators. This gets a slice of the child nodes though, it still gets each child node it returns in its entirety. So in the example of a list of user profiles, this would get a subset of the user profiles, but it's still complete all properties of each user profile node that it returns.

If you tried this and can't get it to work, that'd indeed be a good problem to post to Stack Overflow with a minimal, complete/standalone code sample that reproduces where you are stuck.

Igor Lebedev

unread,
Jan 10, 2023, 10:13:51 AM1/10/23
to Firebase Google Group
Thanks, Frank! 

I successfully use filters and sorting in queries where possible, but in my situation, the combination of normalization and denormalization of the database was not enough for me.
In the snapshot, I get a node containing a list of nodes of the same type, each of which contains a list of the same type of keys and nodes (URL, Like, Dislike, etc.). At the same time, in this snapshot, I am not interested in URLs, but only likes. And URL text fields multiply the traffic and, probably, the load on the server when requested. Apparently, as an option in the future, you can use a combination of Realtime and Firestore at the same time. But I wanted 2 in 1 to simplify.

понедельник, 9 января 2023 г. в 02:10:20 UTC+5, frank.va...@gmail.com:

Frank van Puffelen

unread,
Jan 10, 2023, 10:16:04 AM1/10/23
to Firebase Google Group
If you want to read a subset of the data of each node, consider creating an additional list in the database with only the data that you need. You can either duplicate the data, or store the URLs in one place and the rest of the data in another place. Loading data from multiple paths is not nearly as expensive as you may expect, as the SDKs pipeline requests over a single socket connection.
Reply all
Reply to author
Forward
0 new messages