0

I have a Schema in mongodb like: INPUT

{
  _id: ObjectId("5e05c1089b3e4e333cee8c39"),
  name:"Alex",
  activity:[
        {
            _id: ObjectId("5e05c1089b3e4e333cee8c39"),
            type: 'run',
            start_timestamp: ISODate("2020-01-11T11:34:59.804Z"),
            end_timestamp: ISODate("2020-01-11T11:40:00.804Z")
        },
        {
            _id: ObjectId("5e05c1089b3e4e333cee8c40"),
            type: 'stop',
            start_timestamp: ISODate("2020-01-11T11:40:00.804Z"),
            end_timestamp: ISODate("2020-01-11T11:42:00.804Z")
        },
        {
            _id: ObjectId("5e05c1089b3e4e333cee8c41"),
            type: 'wait',
            start_timestamp: ISODate("2020-01-11T11:42:00.804Z"),
            end_timestamp: ISODate("2020-01-11T11:52:00.804Z")
        },
        {
            _id: ObjectId("5e05c1089b3e4e333cee8c41"),
            type: 'stop',
            start_timestamp: ISODate("2020-01-11T11:52:00.804Z"),
            end_timestamp: ISODate("2020-01-11T12:02:00.804Z")
        },
        {
            _id: ObjectId("5e05c1089b3e4e333cee8c41"),
            type: 'sleep',
            start_timestamp: ISODate("2020-01-11T12:02:00.804Z"),
            end_timestamp: ISODate("2020-01-11T12:48:00.804Z")
        }
  ]
}

This is a schema for a man activity, i need to find brake-up of every 15 minute (brake-up duration in minute),i have found a solution in many forums but there only single timestamp but in my case there are 2 timestamp and first i have to calculate duration and then group by according to 15 minute

Desire output

[
  {
        _id: "2020-01-11T11:34 to 2020-01-11T11:49" ,
        duration: "15 min",
        "brake-up":{
          run:"6 min",
          stop:"2 min",
          wait:"7 min"
        }
   },
   {
        _id: "2020-01-11T11:49 to 2020-01-11T12:04" , 
        duration: 15 min,
        "brake-up":{
          wait:"3 min"
          stop:"10 min"
          sleep:"2 min"
        }
   {
        _id: "2020-01-11T12:04 to 2020-01-11T12:19" , 
        duration: 15 min,
        "brake-up":{
          sleep:"15 min"
        }
   }
]

Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.