Ragul Cs :
Peter Haddad :
Change the structure of the database to the following:
Accounts
userId
randomId
age : 100
name : peter
userId
randomId
age : 120
name : peterx
This way it will be easier to query, now you can do the following:
let ref = firebase.database().ref("Accounts");
let user = firebase.auth().currentUser;
ref.child(user.uid).on("value",(snapshot)=> {
snapshot.forEach((childSnapshot) => {
let childData = childSnapshot.val();
let age = childData.age;
let name = childData.name;
console.log(childData);
});
});
Another way is to remove the randomId and directly access the data without using forEach
.