title: Node js asynchronous mongodb find() query multiple calls
body: <p>I fetched the records using </p>
  
  <blockquote>
    <p>find().toArray()</p>
  </blockquote>
  
  <p>query. In that records, there is relation id of other document(table). I want to get records of relation table of each record of above find query result.
  Like:</p>
  
  <pre><code>   db.collection('serviceBooking').find({'request_to_sp_user_id': docs._id.toString()}).toArray(function (err, serviceBookingDocs) {
          if (serviceBookingDocs.length) {
              var asyncCalls = [];
              serviceBookingDocs.forEach(function (bookingRecord, key) {
                  var temp = {};
                  temp.userDetails = {};
                  //Async call for getting the user details for all users
                  asyncCalls.push(function (callback) {
                      db.collection('userDetails').findOne({'user_id': new mongo.ObjectID(bookingRecord.booked_by_user_id)}, function (err, userDetailsDocs) {
                          db.collection('serviceBookingDetails').find({'serviceBookingId': bookingRecord._id.toString()}).toArray(function (err, bookingDetailsDocs) {
                              if (userDetailsDocs) {
                                  if (bookingDetailsDocs.length) {
                                      temp.bookingDetails = bookingDetailsDocs;
                                      bookingDetailsDocs.forEach(function (bookDetailItems, key) {
                                          db.collection('serviceCatalog').findOne({'_id': new mongo.ObjectID(bookDetailItems.catalogId), isDeleted: 0}, function (err, spCatalogs) {
                                              db.collection('spServiceCatalog').findOne({'_id': new mongo.ObjectID(spCatalogs.serviceCategory)}, function (err, spServiceCatalogDocs) {
                                                  if (spCatalogs) {
                                                      (spServiceCatalogDocs)
                                                      spCatalogs.catalogName = spServiceCatalogDocs.name;
                                                      temp.bookingDetails[key].serviceCatalgs = spCatalogs;
                                                  } else {
                                                      spCatalogs.catalogName = null;
                                                      temp.bookingDetails[key].serviceCatalgs = spCatalogs;
                                                  }
                                                      callback(null, temp);
                                              })
                                          })
                                      })
                                  }
                              } else {
                                  callback(null, null);
                              }
                          })
                      })
                  })
              })
          }
      })
  </code></pre>
  
  <p>I tried with callback function but it not get the values of category name from mainCategory document.
  I also tried to get the internal fetched category name outside the <strong>forEach()</strong> but its not getting in result in <strong>temp</strong> array.</p>