Hi Benny,
Great question! Your analysis seems correct.
In
the end, I think the answer depends on what you are optimizing for. If
the goal is to fetch as little data as possible from the network, then
I'd recommend myTree.child("a").on("value") - and so on for each child
you are interested in. You should use .once() only if you are sure that
you won't need updates
in the future, because if you end up calling .once() a bunch of times,
that could get pretty inefficient (and one of Firebase's salient
features is the ability to get real-time updates!).
On the other
hand, if you anticipate needing child "b" sometime later in the code,
it's probably better to fetch the whole tree with myTree.on("value") -
the same comment about .once() applies.
The second approach would only be needed if you also need to know
when a new child is added, which may or may not be the case in your
application. You might also consider using .on("child_changed") if you
know that there will be a fixed number of children, but want to receive a
callback if their values change.
Feel free to give us more details about your specific use case, and we'd be happy to recommend alternatives!
Cheers,
-Anant