title: How to query a 'join' collection in MongoDb using Node.js?
body: <p>I'm using Node.js and mongoose to query a mongodb database.
  It is very simple scenario but I cannot figure out how to do it properly.</p>
  
  <p>I have a collection to query and then given the result, need to fetch object from another collection to populate the result. code sample as below:</p>
  
  <pre><code>q.exec( function (e, docs){
      if (e || !docs) {
          res.status(400);
          res.send("Error while processing request.\n"+ JSON.stringify(e, null, 4));
      }else{
           //do the JOIN here.
           var result = _(docs).map(
              function(doc){
                  markModel.findOne(
                     {question_id: doc._id, user_id: user_id},
                     function (err, markDoc){
                       if (markDoc)
                          doc.mark = markDoc;
                     });
                //HOW and what to return here??
              });
           res.send(result);
      }
  });
  </code></pre>
  
  <p>In the code above, <code>docs</code> is the result of the first query; and then I need to find the <code>mark</code> from another collection for each of the <code>doc</code> in <code>docs</code>, and attach it to the <code>doc</code> object. Because the second query is also asyn called, I don't know what should be returned in the <code>map()</code> function, without using defer or promise, etc.</p>