In Firebase, ref
and child
are used a lot.
For example - firebase.database().ref('users/<user-id>')
will work exactly same as firebase.database().ref('users').child('<user-id>')
, so what exactly is the difference between them and when should either of them be used?
A Reference represents a specific location in your Database and can be used for reading or writing data to that Database location. You can reference the root or child location in your Database by calling firebase. database(). ref() or firebase.
Show activity on this post. retrieve childs of Day 1 to an array and count the array that ll be the no of child. Show activity on this post. add another lister to days that will give you all matches you played on a day.
A DataSnapshot instance contains data from a Firebase Database location. Any time you read Database data, you receive the data as a DataSnapshot.
addValueEventListener() keep listening to query or database reference it is attached to. But addListenerForSingleValueEvent() executes onDataChange method immediately and after executing that method once, it stops listening to the reference location it is attached to.
There is no difference, in any case you have a DatabaseReference
instance.
A Firebase reference represents a particular location in your Database and can be used for reading or writing data to that Database location.
The method:
public DatabaseReference getReference (String path)
Gets a DatabaseReference for the provided path.
The method:
public DatabaseReference child (String pathString)
Get a reference to location relative to this one.
There is no difference between the two ways you wrote. The only thing is that the first one is a shorthand, where "/" kinda means "child". By the way, the title question you put is not what your question is actually about. "Ref" and "child" are completely different things, because "ref" just makes a reference indicating where the data should go and "child" is specifying the more exact location of that traveling data. I would recommend to change that.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With