ndduong ndduong - 4 months ago 116x
Swift Question

How do I loop through and get all the keys of the nested nodes in firebase?

I am trying to get the keys of the nested nodes in Firebase and I am not sure how to do this.

For example in this case:


How do I know that 2,3,4 exist within 1?

I am thinking of putting a values in a list seperately in firebase. But is there a smarter way of doing this? Is there a more efficient way of getting the keys of all the nested nodes in Firebase?


In Android

Gives access to all of the immediate children of this snapshot. Can be used in native for loops:

for (DataSnapshot child : parent.getChildren()) { 
   //Here you can access the child.getKey()

In iOS

for (child in snapshot.children) { 
  //Here you can access child.key

In Web

snapshot.forEach(function(childSnapshot) {
   //Here you can access  childSnapshot.key

You can put it in a different list or in the same path, the important thing is to keep in mind how much data you are really retrieving when calling an event. And how are you going to query that information... that is why it is recommended in NoSQL to keep flat nodes