I need to calculate the no of records as per some time interval using MongoDB aggregate function. I am showing my collection below.
allocation:
state1 state2 createdDate
test1 test2 2019-08-16T09:41:22.202Z
test1 test2 2019-08-16T09:41:22.202Z
test3 test4 2019-08-16T09:41:22.202Z
test1 test2 2019-08-16T09:41:22.202Z
In my allocation collection I have state1,state2,createdDate
column and here I need to calculate the no of record within some time interval as per user input (i.e-test1 & test2
). Here Using aggregate function I need to the result like below.
difference count
0-6HRs 2
6-12HRS 0
................................
................................
The time difference will calculate from createdDate
column value.
Copyright Notice:Content Author:「satya」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/57709087/calculate-the-count-as-per-time-difference-using-aggregate-function-in-mongodb