i wanted to get the data from two tables in firebase db the 1st table was
from here i want to get the next data from table based on the hospital_fk
this is the result it got on my json
and here is my script for getting the data..
router.get('', function(req, res){
var booths = database.ref('booths');
var hospital = database.ref('hospitals');
booths.once('value', function (snapshot) {
var dataSet = [];
snapshot.forEach(function (childSnapshot) {
var childKey = childSnapshot.key;
var fk = snapshot.child(childKey).val();
hospital.child(childSnapshot.val().hospital_fk).on('value', hospital=>{
var childData = _.assign(fk, hospital.val());
dataSet.push({
childKey: childKey,
childData: childData
});
res.json(dataSet);
});
});
});
});
now my problem was only the first data is being returned and also getting an error.. says that FIREBASE WARNING: Exception was thrown by user callback. Error: Can't set headers after they are sent.
any idea on how to get all the records and what's the best approach on joining two tables.