title: How to implement async in for loop?
body: <p>I have a collection called  'alldetails' which have the details of some collection</p>
  
  <pre><code>{
      "name" : "Test1",
      "table_name" : "collection1",
      "column_name" : "column1"
  },
  {
      "name" : "Test2",
      "table_name" : "collection2",
      "column_name" : "column2"
  },
  {
      "name" : "Test3",
      "table_name" : "collection3",
      "column_name" : "column3"
  }
  </code></pre>
  
  <p>I have collection1,collection2 and collection3 which have column1,column2,colum3 respectively</p>
  
  <p>I have to fetch all the name from the  'alldetails' and I have to get the min and max value of other table based on the column name.</p>
  
  <p>So I want the output like below</p>
  
  <pre><code>{name: ["Test1","Test2","Test3"],
  date: [{min_date: "2018-12-01", max_date: "2018-12-31", name: "Test1"},
                {min_date: "2018-12-01", max_date: "2018-12-31", name: "Test2"},
                {min_date: "2018-12-01", max_date: "2018-12-31", name: "Test3"}]
  
  }
  </code></pre>
  
  <p>I tried the below code because of non blocking its not waiting the response.</p>
  
  <pre><code>alldetails.find({}, { _id: 0 }).then(async function(result) { 
      let result_data = {};  
      let resolvedFinalArray = {};
      let array = [];
      result_data["name"]= [];
      result_data["date"] = [];
      resolvedFinalArray = await Promise.all(result.map(async value =&gt; { 
        result_data["name"].push(value.name)  
        getResult(value.table_name,value.column_name,function(response){
             result_data["date"].push({min_date: response.minvalue, max_date: response.maxvalue, name:value.name})          
         });     
      }));
      setTimeout(function()
      { 
        console.log(resolvedFinalArray);
      }, 3000);
  
  });
  </code></pre>
  
  <p>Please suggest me a solution. </p>