title: Async loop with mongodb nodejs
body: <p>I have 2 collections in MongoDb : <em>users</em> and <em>images</em></p>
  
  <p><strong>users</strong> is like :</p>
  
  <pre><code>{
  "_id": ObjectID("58299fc14705d47ff852f8ae"),
  "mail": "Qwerty1@test.test",
  "username": "Qwerty1",
  "token": "g8m7h0phrvhp774cw0xh9qkt9rhu062r2b3gigm0t1o22zkt9",
   ...,
  "images": [
      ObjectID("582c547bb7c5cc391e5a1793"),
      ObjectID("582c54ecb7c5cc391e5a1794")
  ]
  }
  </code></pre>
  
  <p><strong>images</strong> is like :</p>
  
  <pre><code>{
  "_id": ObjectID("582c5394b522cb37d701dbe3"),
  "user": "g8m7h0phrvhp774cw0xh9qkt9rhu06
  "image": base64 encoded
  }
  </code></pre>
  
  <p>I make a find in <em>users</em> to get ids of this user's images and I want to fill an array (
      b64Images
  ) with a a find request to <em>images</em> collection.</p>
  
  <pre><code>db.collection("users").find({$or : [{ username: req.params.username }, {token : req.params.username}]}).toArray(function (err, result) {
     if(result.length){
        var b64Images = [];
        async.each(result[0].images,
        function(item, callback){
           db.collection("images").find({_id : item}).toArray(function (err, resulta) {
              console.log(resulta[0].user);
              b64Images.push(resulta[0].user);
           });
           callback();
        },
        function(err){
           console.log("finished");
           res.json({images : b64Images});
        }
     }
  }
  </code></pre>
  
  <p>But my problem is that my loop is finished before my find in <em>images</em>'s response.</p>
  
  <p>So I have an empty array.</p>
  
  <p>I know this is an asynchronous problem but I can't figure it out.</p>