title: Node.js async map over MongoDB queries
body: <p>I'm having a problem with <code>async</code> Node.js module. In my Node.js app, I'm trying to get an array of JSON objects returned by a MongoDB request:</p>
  
  <pre><code>var fruits = ["Peach", "Banana", "Strawberry"];
  var finalTab = [];
  fruits.forEach(function(fruit) {
      db.collection('mycollection').distinct("column1", {"column2":{$regex :fruit}}, (function(err, result) {                 
          finalTab[fruit] = result;
          console.log(result); // -&gt; display the desired content
          db.close();
          if (err) throw err;
      }));
  });
  console.log(finalTab); // -&gt; []
  </code></pre>
  
  <p>At the moment, I'm at this point.</p>
  
  <p>I'm trying to implement the <code>async.map</code> to iterate through <code>Fruits</code> collection.
  <a href="https://caolan.github.io/async/docs.html#map" rel="nofollow noreferrer">https://caolan.github.io/async/docs.html#map</a></p>
  
  <p>Can someone help? :)</p>
  
  <p>Thanks by advance for help.</p>
  
  <p>EDIT: 
  As I need all results returned by my <code>db.collection</code> functions, I'm trying to add these async commands to a queue, execute it and get a callback function.</p>