3 / 3
May 2024

I am using mongoose with node Js.
Count operation is taking huge time with 15 million records taking around 1 minutes.

Aggregate Query : [{“$match”:{“createdAt”:{“$gte”:“2024-05-01T00:00:00.000Z”,“$lte”:“2024-05-16T00:00:00.000Z”},“user_id”:“62943f06a21bb047f3d42e0d”}},{“$count”:“count”}]

Another option tried : [{“$match”:{“createdAt”:{“$gte”:“2024-05-01T00:00:00.000Z”,“$lte”:“2024-05-16T00:00:00.000Z”},“user_id”:“62943f06a21bb047f3d42e0d”}},{$group: { _id: null, count: {$sum: 1}}}]