Reputation: 143
I am new to react native and I am using the Firebase Realtime database. I am trying to fetch all the 'sleep' values from the firebase db - as shown in this screenshot.
I could proceed till here -
constructor(props) {
super(props);
var sleep = db.ref('symptoms/');
sleep.on('value', function(snapshot) {
console.log(snapshot.val());
});
}
and fetch all the data in the symptoms tree as so -
But I am only interested in fetching the sleep values which are inside these random keys. I don't know how to navigate through the keys - specially when new keys are generated when a new child gets added - and I want to be able to fetch the newly added child as well.
Does anyone know how to do this ?
Upvotes: 1
Views: 220
Reputation: 80934
You need to iterate to retrieve the sleep value:
constructor(props) {
super(props);
var sleep = db.ref('symptoms/');
sleep.on('value', function(snapshot) {
snapshot.forEach((childSnapshot) => {
console.log(childSnapshot.val().sleep);
});
});
}
Upvotes: 1