Mongodb Aggregation returning Data for every hour and counting on a particular field if its value is 2,3,1

Viewed 10

I have the following collection:

{
    "_id" : "001320b316874f63adf4016a67eb26e",
    "first_name" : "ajdasd",
    "last_name" : "akjdsajd",
    "is_staff" : false,
    "is_superuser" : false,
    "username" : "kajfghdjsag564656",
    "password" : "$2a$12$R/L5tNDzXoAuhPG5Br/U4Onoz1Id9aiivrAVJtzy8jWz3I/HeMlAi",
    "email" : "rinonab766@ulforex.com",
    "dial_code" : "+91",
    "phone_number" : "54531852773",
    "user_type" : 2,
    "device_info" : {
        "device_id" : null,
        "device_type" : null
    },
    "role_id" : "383544a353da48eb8044fc334db99d92",
    "kyc_process_status" : 2,
    
    "created_date" : NumberLong(1646306732)
},{
    "_id" : "001320b316874f63adf4016a67eb286",
    "first_name" : "ajdasd",
    "last_name" : "akjdsajd",
    "is_staff" : false,
    "is_superuser" : false,
    "username" : "kajfghdjsag564656",
    "password" : "$2a$12$R/L5tNDzXoAuhPG5Br/U4Onoz1Id9aiivrAVJtzy8jWz3I/HeMlAi",
    "email" : "rinonab766@ulforex.com",
    "dial_code" : "+91",
    "phone_number" : "54531852773",
    "user_type" : 2,
    "device_info" : {
        "device_id" : null,
        "device_type" : null
    },
    "role_id" : "383544a353da48eb8044fc334db99d92",
    "kyc_process_status" : 1,
    
    "created_date" : NumberLong(1646306732)
},{
    "_id" : "00132b316874f63adf4016a67eb286e",
    "first_name" : "ajdasd",
    "last_name" : "akjdsajd",
    "is_staff" : false,
    "is_superuser" : false,
    "username" : "kajfghdjsag564656",
    "password" : "$2a$12$R/L5tNDzXoAuhPG5Br/U4Onoz1Id9aiivrAVJtzy8jWz3I/HeMlAi",
    "email" : "rinonab766@ulforex.com",
    "dial_code" : "+91",
    "phone_number" : "54531852773",
    "user_type" : 2,
    "device_info" : {
        "device_id" : null,
        "device_type" : null
    },
    "role_id" : "383544a353da48eb8044fc334db99d92",
    "kyc_process_status" : 1,
    
    "created_date" : NumberLong(1646306732)
}

I want the following output for every hour with 24 hour time period:

{
timestamp:1646306732,
pendingcount:5,(count of kyc_process_status=2)
verifiedcount:4,(count of kyc_process_status=1)
totalcount:9(total count)
}
kyc_proccess_status=1(verified)
kyc_process_status=2(pending)
0 Answers
Related