title: How do you retrieve "related" documents in MongoDB?
body: <p>I'm using node.js, express, and MongoSkin driver for MongoDB.</p>
  
  <p>I'm trying to render a view in my blog application that shows a list of blog posts. Each post has a reference to an author ID. I'm trying to make a second query for each post to get the full author document for each reference. Everything being asynchronous is confusing me quite a bit.</p>
  
  <p>On the callback for getting the list of blog posts I'm then looping through each post and making a second call to get the associated user. I don't know how to only render the view once all posts have had their author document added to it. I'm not even sure I'm doing any of this right. How to I reference other documents to accomplish what I want to do?</p>
  
  <pre><code>// getPageOfPosts is a custom helper that accepts the page number and number of items to retrieve.
  db.collection('blogPosts').getPageOfPosts(req.param('page') || 1, 3, function (err, blogPosts) {
      if (err) req.next(err);
      blogPosts.forEach(function (blogPost) {
          db.collection('users').findOne({ _id: blogPost.authorId }, function (err, user) {
              if (err) req.next(err);
              blogPost.author = user;
          });
      });
      var viewModel = {
          posts: blogPosts
      };
      res.render('blog/index', viewModel);
  });
  </code></pre>