i have a firebase database where as i want to read parent=>child and parent==>child==>child as shown in the attached screenshot
Code that reads parent==>child (finance,userid,email...) successfuly
try
{
const dbref = ref(db);
get(child(dbref,"finance")).then((snapshot)=>
{
var client=[];
snapshot.forEach(childSnapshot =>
{
const data = childSnapshot.val();
client.push(data);
});
AddAllItemsToTable(client);
});
How can i read finance==>userid==>id==>value1,value2
"finance": {
"lvAN928K9qXJ5RGiRBUrb6seByM2": {
"-N6XXgy0COp30w52pxzZ": {
"link": "https://firebasestorage.googleapis.com/v0/b/myhouse-4ba96.appspot.com/o/Documentdocument%3A76094?alt=media&token=5fc3eda7-00ed-4a47-a6e0-1f89dfdabca9"
},
"-N6XXh2rkW0jT7MNpO2-": {
"link": "https://firebasestorage.googleapis.com/v0/b/myhouse-4ba96.appspot.com/o/Documentdocument%3A76093?alt=media&token=7e2e59ea-7821-4a8b-8b93-9fe17b4b1118"
},
"email": "app@email.com",
"houseContractor": "General construction ",
"houseCost": "2400000",
"income": "1200000",
"institution": "Commercial Banks",
"nic": "123456789",
"permit": "Yes"
}
}
I have tried
try
{
const dbref = ref(db);
get(child(dbref,"finance")).then((snapshot)=>
{
var client=[];
snapshot.forEach(childSnapshot =>{
let item1=childSnapshot.val();
client.push(item1);
childSnapshot.forEach((grandchildSnapshot) =>{
let item=grandchildSnapshot.val()
item.key=grandchildSnapshot.key
client.push(item)
});
});
AddAllItemsToTable(client);
});
In your current structure all you can do to get to the links is to loop over all child nodes again:
const dbref = ref(db);
get(child(dbref,"finance")).then((snapshot)=>{
var client=[];
snapshot.forEach(childSnapshot => {
childSnapshot.forEach((grandchildSnapshot) => {
if (grandchildSnapshot.hasChild("link")) {
console.log(grandchildSnapshot.child("link").val());
})
})
})
})