title: Node.js - Async.js map function only showing results of the first iteration?
body: <p>I'm mapping an array when I finish the mapping I should  return the whole array, but in my code the first element that it return.</p>
  
  <blockquote>
    <p>In this function I'm using async.map to call getShippingMethods function, after getting the result I'm calling resolve function, but the problem the resolve function return just the first element of the array.</p>
  </blockquote>
  
  <pre><code>   function getShippingZones() {
          return new Promise((resolve, reject) =&gt; {
              pool.getConnection(function (error, connection) {
                  if (error) reject("error in connection")
                  else {
                      connection.query("select * from shipping_zone", function (error, result, fields) {
                          if (error) reject(error)
                          else {
                              async.map(result, getShippingMethods, function (res) {
                                  resolve(res)
                              })
                          }
                      })
                  }
              })
          })
      }
  
  
  
  
  
     function getShippingMethods(result, callback) {
      pool.getConnection(function (error, connection) {
          if (error) return (error)
          else {
              var id = result.id
              var name = result.zone_name
              console.log("zone name", name)
              var query1 = "SELECT sm.id, method_name, rate_amount, rate_min, rate_max, delivry_min, delivry_max, shipping_zone_id, factors_id, factor_name FROM `shipping_method` sm, `factors` f  where sm.shipping_zone_id = " + id + " and f.id = sm.factors_id"
              var query2 = "SELECT * FROM `country` WHERE shipping_zone_id = " + id
              connection.query(query1 + ";" + query2, function (error, results, fields) {
                  var shippingMethods = results[0].map(_getShippingMethod);
                  var countries = results[1].map(_getShippedCountries)
                  callback({ id: id, name: name, shippingMethods: shippingMethods, countries: countries });
              });
          }
      })
  }
  
  
  function _getShippingMethod(result) {
      return {
          id: result.id,
          methodName: result.method_name,
          rateAmount: result.rate_amount,
          rateMin: result.rate_min,
          rateMax: result.rate_max,
          deliveryMin: result.delivry_min,
          deliveryMax: result.delivry_max,
          factorName: {
              id: result.factors_id,
              name: result.factor_name
          }
      };
  }
  
  
  function _getShippedCountries(result) {
      return {
          id: result.id,
          name: result.name,
          countryCode: result.country_code
      };
  }
  </code></pre>