title: How to calculate using data from previous object and current object in mongodb array of objects using aggregate?
body: <p>I have the following data in mongodb</p>
  
  <pre><code>  { 
      "_id" : ObjectId("5641f77344aef29028a86d9b"), 
      "timestamp" : "2015-09-21 00:01:34",  
      "day_chan1" : NumberInt(0), 
      "day_chan2" : NumberInt(0), 
      "day_chan3" : NumberInt(65), 
      "gatwayId" : "4437191001a3"
  }
  { 
      "_id" : ObjectId("5641f77344aef29028a86d9c"), 
      "timestamp" : "2015-09-21 00:02:34",     
      "day_chan1" : NumberInt(0), 
      "day_chan2" : NumberInt(0), 
      "day_chan3" : NumberInt(97), 
      "gatwayId" : "4437191001a3"
  }
  { 
      "_id" : ObjectId("5641f77344aef29028a86d9d"), 
      "timestamp" : "2015-09-21 00:03:34", 
      "day_chan1" : NumberInt(0), 
      "day_chan2" : NumberInt(0), 
      "day_chan3" : NumberInt(130), 
      "gatwayId" : "4437191001a3"
  }
  </code></pre>
  
  <p>and I want to calculate three extra fields ph1,ph2,ph3 from the given data where <code>ph1 = day_chan1 of current - day_chan2 of previous object</code>. Can this be done using aggregate in mongoose or pure mongodb ?  </p>