Best aggregate approach regarding a query on lakhs of doc in a collection

Hi,
suppose if I am having lakhs of doc in a collection like this.

collection example:

{
    {
      userName: "cary"
      time: 50
      userId: 1
    }
    {
      userName: "john"
      time: 40
      userId: 1
    }
    {
      userName: "bliss"
      time: 50
      userId: 1
    }
    {
      userName: "ross"
      time: 40
      userId: 1
    }
}

I have to query in this collection such as I will get the count of users whose time is less than 40,50,60

result example:

{
time: UsersCountWithPrticularTime,
‘40’: 150,
‘50’: 50,
‘60’: 75,
‘40’: 90,

}

Any idea of how can I acheive this

I think that what you want can be done using $bucket.

1 Like

@Mohammad_Farhan, please share your final approach so that others find the forum useful.

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.