I want to group the data based on the values of the “ignition” field. If the “ignition” value is 1, all records with the value 1 should be grouped together until the next value of 0 is encountered, and so on.
I have 86400 records in MongoDB, and I want to query the data to achieve the desired output.
[
{
ignition: 1,
time: 112
},
{
ignition: 1,
time: 193
},
{
ignition: 0,
time: 115
},
{
ignition: 1,
time: 116
},
{
ignition: 1,
time: 117
},
{
ignition: 1,
time: 118
},
{
ignition: 0,
time: 119
},
{
ignition: 1,
time: 120
},
{
ignition: 1,
time: 121
},
{
ignition: 1,
time: 122
},
{
ignition: 0,
time: 123
},
]
I want the output like this:
{
time: [112,193],
time: [116,117,118],
time: [120,121,122]
}