Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get child name from Firebase?

If I have something like:

child name: "value" 

How can I get the childname? I know its possible to get the value, but what about the other?

like image 971
august alsina Avatar asked Oct 18 '16 06:10

august alsina


People also ask

How to fetch data from Firebase db?

Firebase data is retrieved by either a one time call to GetValueAsync() or attaching to an event on a FirebaseDatabase reference. The event listener is called once for the initial state of the data and again anytime the data changes.

Can I query Firebase database?

Querying DataWith Firebase database queries, you can selectively retrieve data based on various factors. To construct a query in your database, you start by specifying how you want your data to be ordered using one of the ordering functions: orderByChild() , orderByKey() , or orderByValue() .

How to get value from snapshot Firebase?

You can extract the contents of the snapshot as a JavaScript object by calling the val() method. Alternatively, you can traverse into the snapshot by calling child() to return child snapshots (which you could then call val() on).


1 Answers

The child name in this situation is the "KEY" of that value. So use the reference object and call getKey() on it.

String name = ref.getKey();
like image 125
fsebek Avatar answered Sep 30 '22 05:09

fsebek