title: how to make multiple table join in firebase in node js
body: <p>I have multiple table's that i wanted to join based on the id of the main table.
  this is my script.</p>
  
  <pre><code>var bookinghistory = database.ref('bookingHistory');
  var hospital = database.ref('hospitals');
  var client = database.ref('clients');
  var patient = database.ref('patients');
  
  bookinghistory.once('value', function (snapshot) {
          var promises = [];
          snapshot.forEach(function (childSnapshot) {
  
              var childKey = childSnapshot.key;
              var fk = snapshot.child(childKey).val();
  
              var myhospital = hospital.child(childSnapshot.val().hospital_fk).once('value');
              var myclient = client.child(childSnapshot.val().client_fk).once('value');
              var mypatient = patient.child(childSnapshot.val().patient_id).once('value');
  
              promises.push(new Promise((resolve, reject) =&gt; {
                   myhospital.then(docResult =&gt; {
                      resolve({         
                          childKey: childKey,
                          bookhistory: fk,
                          hospital: docResult
                      });
                  }).catch(reason =&gt; {
                      reject(reason);
                   });
               }));
              promises.push(new Promise((resolve, reject) =&gt; {
                   myclient.then(docResult =&gt; {
                      resolve({         
                          client: docResult
                      });
                  }).catch(reason =&gt; {
                      reject(reason);
                   });
               }));
              promises.push(new Promise((resolve, reject) =&gt; {
                   mypatient.then(docResult =&gt; {
                      resolve({         
                          patient: docResult
                      });
                  }).catch(reason =&gt; {
                      reject(reason);
                   });
               }));
         }));
  });
  Promise.all(promises).then(function(snapshots) {
          var dataSet = [];
           snapshots.forEach(function(hospital) {
  
              dataSet.push({
                  childKey: hospital.childKey, 
                  booth: hospital.booth,
                  hospital:hospital.hospital,
                  client:hospital.client,
                  patient:hospital.patient
  
              });
  
          });
          res.json(dataSet);
      });
  </code></pre>
  
  <p>and this is the result of my script.</p>
  
  <pre><code>[
      {
          "childKey": "-L2snm8lhye",
          "hospital": {
              "address": "Rizal Drive cor. ",
              "city": "",
              "createdAt": "2018-01-14 23:01:32",
              "deletedAt": "",
              "latitude": "14.554928",
              "longitude": "1115",
              "name": "St. Luke's Medical Center - Global City",
              "province": "",
              "updatedAt": ""
          }
      },
      {
          "client": {
              "createdAt": "2018-01-15",
              "firstName": "",
              "identifier": "+63933000000",
              "lastName": ""
          }
      },
      {
          "patient": {
              "birthdate": "1993-01-15",
              "client_fk": "qFUJT05B19NgQ2",
              "createdAt": "2018-01-15 15:02:13",
              "deletedAt": "",
              "firstName": "Eric Christian",
              "gender": "1",
              "lastName": "Odulio",
              "updatedAt": ""
          }
      }
  ]
  </code></pre>
  
  <p>what i wanted is client,patient data show be after the hospital array.. what happen is it goes outside.. this is the json that i wanted to be returned.. is there any way to do this?. </p>
  
  <pre><code>[
      {
          "childKey": "-L2snm8lhye",
          "hospital": {
              "address": "Rizal Drive cor. ",
              "city": "",
              "createdAt": "2018-01-14 23:01:32",
              "deletedAt": "",
              "latitude": "14.554928",
              "longitude": "1115",
              "name": "St. Luke's Medical Center - Global City",
              "province": "",
              "updatedAt": ""
          }
          "client": {
              "createdAt": "2018-01-15",
              "firstName": "",
              "identifier": "+63933000000",
              "lastName": ""
          }
          "patient": {
              "birthdate": "1993-01-15",
              "client_fk": "qFUJT05B19NgQ2",
              "createdAt": "2018-01-15 15:02:13",
              "deletedAt": "",
              "firstName": "Eric",
              "gender": "1",
              "lastName": "Odulio",
              "updatedAt": ""
          }
     }
  ]
  </code></pre>