Mongo Playground

Configuration

[{source:"itemLineView",createdAt:ISODate("2021-02-17T10:17:11.837Z"),url:"https://mongoplayground.net/"},{source:"itemLineView",createdAt:ISODate("2021-02-17T10:17:11.837Z"),url:"https://mongoplayground.net/1"},{source:"itemLineView",createdAt:ISODate("2021-02-17T10:17:11.837Z"),url:"https://mongoplayground.net/1"},{source:"itemLineView",createdAt:ISODate("2021-02-17T10:17:11.837Z"),url:"https://mongoplayground.net/"},{source:"itemLineView",createdAt:ISODate("2021-02-17T10:17:11.837Z"),url:"https://mongoplayground.net/2"}]

Query

db.collection.aggregate([{$match:{source:"itemLineView",url:{$regex:"mongo"},}},{$group:{_id:{month:{$month:"$createdAt"},day:{$dayOfMonth:"$createdAt"},year:{$year:"$createdAt"},url:"$url"},count:{$sum:1}}},{$group:{_id:{month:"$_id.month",day:"$_id.day",year:"$_id.year",},urls:{$push:{url:"$_id.url",count:"$count"}},count:{$sum:"$count"}}}])

Result