Firebase - What is the difference between ref and child?

gegobyte picture gegobyte · Jul 29, 2016 · Viewed 13.3k times · Source

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?

Answer

Gabriele Mariotti picture Gabriele Mariotti · Jul 29, 2016

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.