title: MongoDB : Is there a way to detect a value trend using aggregation?
body: <p>I'm trying to detect the "trend" of a value in a collection.</p>
  
  <p>Let's say I have the following:</p>
  
  <pre><code>{ created_at: 2014-12-01, value:1015 }
  { created_at: 2014-12-01, value:1015 }
  { created_at: 2014-12-01, value:1019 }
  { created_at: 2014-12-02, value:1018 }
  { created_at: 2014-12-02, value:1021 }
  { created_at: 2014-12-03, value:1010 }
  { created_at: 2014-12-03, value:1012 }
  { created_at: 2014-12-03, value:1011 }
  { created_at: 2014-12-04, value:1012 }
  </code></pre>
  
  <p>I just want to have an output like:</p>
  
  <pre><code>{ created_at: 2014-12-01, average: 1016, diff: 0}
  { created_at: 2014-12-02, average: 1019, diff: 3}
  </code></pre>
  
  <p>With diff being the difference of the average value between
  the two dates.</p>
  
  <p>I figured out how to calculate the averages, find min/max and first/last values in the collection, but can't find a way to compare the two averages...</p>