1
What’s the difference between ref()
and child()
firebase? When should I use one or the other? Is there any difference in performance?
1
What’s the difference between ref()
and child()
firebase? When should I use one or the other? Is there any difference in performance?
1
The 2 are methods of different classes, but return the same thing: a Reference. The ref()
is of class Database and the child()
class Reference.
Let’s see how these methods work:
ref()
- returns a reference to the database node passed as parameter. If it has no specified parameter, it returns the reference to the root node of the database.child()
- also returns a reference to a database node. But the difference is that it serves to access the sub-nodes within a Reference.Bearing in mind that the child()
is from the Reference class and also returns a Reference object, you can use chained Childs as follows:
ref.child("users").child("uid1").child("nome")
But the same does not happen with the ref()
. Is not possible do ref.ref("users").ref("uid1").ref("nome")
.
It is also possible to access the sub-nodes using the ref()
:
ref = database.ref("users/uid1/nome");
And using the child()
:
ref = database.ref().child("users/uid1/nome");
//ou até
ref = database.ref("users").child("uid1/nome")
In short: In the end, the 2 methods return the same thing and have no difference in terms of performance. Use the method that makes you more comfortable.
Browser other questions tagged javascript firebase realtime-database
You are not signed in. Login or sign up in order to post.
There’s a difference in performance
chlid('a/b')
andchild('a').child('b')
?– Costamilam
There is nothing documented by Firebase. But if you have any difference will be minimal and negligible.
– Rosário Pereira Fernandes