title: nodejs return array of objects from mongodb
body: <p>I want to return an array of objects that contains collection name and its documents count for each object, e.g. 
  [ { col:col1, count:1 } , { col:col2, count:2} ]</p>
  
  <p>Currently I only return an array of document count for each collection, by resolving the query as a promise.</p>
  
  <p>My main issue is returning an object from the .map function because it must return promises instead.</p>
  
  <pre><code>db.listCollections()
    .toArray()
    .then(collections =&gt; {
      let promises = collections.map(col =&gt; {
  
        // Cannot return {col,count} here :/
        return db.collection(col["name"]).countDocuments();
      });
      return Promise.all(promises);
    })
    .then(res =&gt; console.log(res));
  </code></pre>