title: Retrieving an embedded document
body: <p>If I had a document called Category, which embeds many SubCategory documents... what's the best way to retrieve a SubCategory (for example based on ID).</p>
  
  <p>This doesn't work using a DocumentRepository. I am aware that this is a present limitation of MongoDB and I've already voted on <a href="http://jira.mongodb.org/browse/SERVER-142" rel="nofollow">virtual collections</a>.</p>
  
  <p>So I'm wondering what the best way to retrieve a SubCategory is. My current approach looks like this:</p>
  
  <pre><code>&lt;?php
  
  $category = $dm-&gt;createQueryBuilder('Category')
                  -&gt;field('subCategories._id', new \MongoId($id))
              -&gt;getQuery()-&gt;getSingleResult();
  
  foreach($category-&gt;getSubCategories() as $sub){
      if($sub-&gt;getId() === $id){
          $subCategory = $sub;
          break;
      }
  }
  </code></pre>