Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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:

example

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?

like image 800
ndduong Avatar asked Jun 03 '16 04:06

ndduong


People also ask

How do I get a key in Firebase?

Firebase automatically creates API keys for your project when you do any of the following: Create a Firebase project > Browser key auto-created. Create a Firebase Apple App > iOS key auto-created. Create a Firebase Android App > Android key auto-created.

What is simultaneous connections in Firebase?

A simultaneous connection is equivalent to one mobile device, browser tab, or server app connected to the database. This isn't the same as the total number of users of your app, because your users don't all connect at once.

Which method will write or replace data on a specified path in Firebase?

Using set() overwrites data at the specified location, including any child nodes.

Can we store array in Firebase?

This is because Firebase does not support Arrays directly, but it creates a list of objects with integers as key names.


1 Answers

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

Swift 3:

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

Swift 4:

snapshot.children.forEach({ (child) in
  <#code#>
})

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

like image 94
Ymmanuel Avatar answered Oct 25 '22 16:10

Ymmanuel