如何使用聚合计算使用mongodb对象数组中的先前对象和当前对象的数据?

时间:2015-11-18 10:18:30

标签: node.js mongodb mongoose mongodb-query aggregation-framework

我在mongodb中有以下数据

  { 
    "_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"
}

我想从给定数据ph1 = day_chan1 of current - day_chan2 of previous object计算三个额外的字段ph1,ph2,ph3。这可以使用mongoose或纯mongodb中的聚合物来完成吗?

0 个答案:

没有答案