下面是我的示例数据:(父JSON具有楼层信息,每个楼层具有多个传感器信息)
{"Floor_Id": "Galileo_001",
"name": "Forklifts",
"Sensor_data": [{
"Floor_Id": "Galileo_001",
"Floor_name": "Forklifts",
"Name": "forkLift_002",
"Asset_Id": 123,
"Load": 1.7096133,
"Timestamp": 1537878750996
},
{
"Floor_Id": "Galileo_001",
"Floor_name": "Forklifts",
"Name": "forkLift_003",
"Asset_Id": 456,
"Load": 1.7096133,
"Timestamp": 1537878750996,
},
{
"Floor_Id": "Galileo_001",
"Floor_name": "Forklifts",
"Name": "forkLift_005 ",
"Asset_Id": 127,
"Load": 1.7096133,
"Timestamp": 1537878750996
},
{
"Floor_Id": "Galileo_001",
"Floor_name": "Forklifts",
"Name": "forkLift_001",
"Asset_Id": 157,
"Load": 1.7096133,
"Timestamp": 1537878750996,
}
]}
我想计算地板的总负载,总距离和有源传感器。每天都有类似的信息(每个楼层的总负载和总距离)。所需的响应是这样的:
{
"TotalLoad": 3214,
"Active_no_of_sensor":5,
"Floor_Id": "Galileo_001",
"LoadUnit": "Kgs",
"AssetStatus": [{
"TotalLoad": 200,
"LoadUnit": "Kgs",
"Date": "1539588994"
}, {
"TotalLoad": 400,
"LoadUnit": "Kgs",
"Date": "1539475200"
}, {
"TotalLoad": 100,
"LoadUnit": "Kgs",
"Date": "1539388800"
}]
}
在NiFi中,我有两个单独的运行mongo聚合处理器。
对于第二种情况,我使用以下查询:
[{"$unwind" : "$Sensor_data" },
{"$match": {"Floor_Id" : {"$eq": "${http.param.floorid}"}}},
{"$group": {
"_id": {"Floor_Id": "$Floor_Id",
"DailyDate":{"$dateFromParts":{
"year":{"$year":{"$add": [ISODate("1970-01-01"), "$Sensor_data.Timestamp"]}},
"month":{"$month":{"$add": [ISODate("1970-01-01"), "$Sensor_data.Timestamp"]}},
"day":{"$dayOfMonth":{"$add": [ISODate("1970-01-01"), "$Sensor_data.Timestamp"]}}
}
}
},
"AssetLoad": {"$sum": "$Sensor_data.Load" },
"AssetDistance": {"$sum" : {"$subtract": [{"$toDecimal":"$Sensor_data.End_odometer"},
{"$toDecimal":"$Sensor_data.Start_odometer"}]}}
}
},
{
"$group" : {
"_id": {"Floor_Id": "$_id.Floor_Id"},
"TotalLoad": { "$sum": "$AssetLoad" },
"TotalDistance" : { "$sum": "$AssetDistance" },
"AssetStatus":{
"$push":{
"TotalLoad": "$AssetLoad",
"LoadUnit": "Kgs",
"TotalDistance" : "$AssetDistance",
"Date": "$_id.DailyDate"
}
}
}
},
{"$project" : {
_id:0,
"AssetStatus" : 1
}
}]
错误
处理器显示'Error running mongodb aggregation query: Unrecognized Token ISODate: was expecting null, true, false or NaN'
如何解决此问题? (我不想将集合中的日期格式从BSON Long更新为ISODate)
答案 0 :(得分:0)
已解决
在Run Mongo Aggregation处理器中用$ convert运算符替换了ISODate