title: How to compare grouped data between two dates using the mongodb aggregate framework
body: <p>Consider a data set as follows</p>
  
  <pre><code>Sector Value Date
  a      2     1/1/2015
  b      5     1/1/2015
  c      8     1/1/2015 
  a      3     1/1/2015
  a      6     1/1/2015
  a      1     1/1/2015
  c      1     1/1/2015
  
  Sector Value Date
  a      2     2/1/2015
  b      10    2/1/2015
  b      5     2/1/2015
  c      8     2/1/2015
  </code></pre>
  
  <p>Is there a way to use the MongoDB aggregate framework to find the <em>difference</em> between each grouped sector for the two dates in question?</p>
  
  <p>In other words is it possible to get an output like this:</p>
  
  <pre><code>a    -&gt; (2+3+6) - 2 = 10 
  b    -&gt; 5 - (10+5) = -10
  c    -&gt; (8+1) - 8 = 1
  </code></pre>