title: How do I aggregate two nested documents?
body: <p>Since Video has embeds_many dates, and dates has embeds_many countries. Using the aggregation framework, how would I get the total of all <code>likes_count</code>?</p>
  
  <p>I got the following structure:</p>
  
  <pre><code>{ "_id" : ObjectId( "5190fbbc72357e713900001b" ),
    "dates" : [ 
      { "_id" : ObjectId( "5190fbbc72357e713900001c" ),
        "countries" : [ 
          { "_id" : ObjectId( "5190fbbc72357e713900001d" ),
            "unique_views_count" : 500,
            "non_unique_views_count" : 1000,
            "likes_count" : 1,
            "comments_count" : 1,
            "iso_two_letter_country_code" : "US",
            "country_name" : "United States" }, 
          { "_id" : ObjectId( "5190fbbc72357e713900001e" ),
            "unique_views_count" : 300,
            "non_unique_views_count" : 777,
            "likes_count" : 0,
            "comments_count" : 0,
            "iso_two_letter_country_code" : "UK",
            "country_name" : "United Kingdom" } ],
        "date" : 20130513 } ],
    "video_id" : 1 }
  </code></pre>
  
  <p>So far I have tried, to no avail:</p>
  
  <pre><code>Video.collection.aggregate(
    { '$unwind' =&gt; '$dates.countries'},
    {
      '$group' =&gt; {
        '_id' =&gt; '$_id'
        'likes' =&gt; { '$sum' =&gt; '$dates.countries.likes_count' }
      }
    }
  )
  </code></pre>