Hi, one of my queries have a result like this. I need to further process the result set by subquerying this result’s query.
Second item in the events list depends on the first events item.
If an item inside second events array does not have a correspondence with same device id and same day in the first events object, we need to filter it out. So the final result set must be sth like the second result set below. How I can do it? Maybe you can advice me to construct a different result set before this operation… My simple goal is to check if a device executed the second step in the same day of the execution of the first step of this device.
[
{
"events": [
{
"createdAt": "2017-02-08T08:53:19.879Z",
"deviceId": "00000000-555a-4ce5-ffff-ffffaa4fac17",
"stepNo": 0
},
{
"createdAt": "2017-02-09T08:09:16.597Z",
"deviceId": "00000000-555a-4ce5-ffff-ffffaa4fac17",
"stepNo": 0
}
],
"stepNo": 0
},
{
"events": [
{
"createdAt": "2017-02-08T08:36:49.404Z",
"deviceId": "00000000-555a-4ce5-ffff-ffffaa4fac17",
"stepNo": 1
},
{
"createdAt": "2017-03-21T10:48:47.769Z",
"deviceId": "00000000-555a-4ce5-ffff-ffffaa4fac17",
"stepNo": 1
},
{
"createdAt": "2017-03-21T12:01:31.638Z",
"deviceId": "00000000-555a-4ce5-ffff-ffffe6e46228",
"stepNo": 1
},
{
"createdAt": "2017-03-21T12:34:15.345Z",
"deviceId": "00000000-555a-4ce5-ffff-ffffe6e46228",
"stepNo": 1
}
],
"stepNo": 1
}
]
Final output:
[
{
"events": [
{
"createdAt": "2017-02-08T08:53:19.879Z",
"deviceId": "00000000-555a-4ce5-ffff-ffffaa4fac17",
"stepNo": 0
},
{
"createdAt": "2017-02-09T08:09:16.597Z",
"deviceId": "00000000-555a-4ce5-ffff-ffffaa4fac17",
"stepNo": 0
}
],
"stepNo": 0
},
{
"events": [
{
"createdAt": "2017-02-08T08:36:49.404Z",
"deviceId": "00000000-555a-4ce5-ffff-ffffaa4fac17",
"stepNo": 1
}
],
"stepNo": 1
}
]