Database
db={"users":[{_id:"123"},{_id:"456"}],"questions":[{authorId:"123",createdAt:ISODate("2022-09-01T00:00:00Z")},{authorId:"456",createdAt:ISODate("2022-09-05T00:00:00Z")},],"answers":[{authorId:"123",createdAt:ISODate("2022-09-01T08:00:00Z")},{authorId:"456",createdAt:ISODate("2022-09-05T08:00:00Z")},],"comments":[{authorId:"123",createdAt:ISODate("2022-09-01T16:00:00Z")},{authorId:"456",createdAt:ISODate("2022-09-05T16:00:00Z")},],}
Query
db.users.aggregate([{"$lookup":{"from":"questions","localField":"_id","foreignField":"authorId","as":"questions"}},{"$lookup":{"from":"answers","localField":"_id","foreignField":"authorId","as":"answers"}},{"$lookup":{"from":"comments","localField":"_id","foreignField":"authorId","as":"comments"}},{"$project":{questionCount:{"$size":{"$filter":{"input":"$questions","as":"item","cond":{"$gt":["$$item.createdAt",ISODate("2022-09-03T00:00:00Z")]}}}},answerCount:{"$size":{"$filter":{"input":"$answers","as":"item","cond":{"$gt":["$$item.createdAt",ISODate("2022-09-03T00:00:00Z")]}}}},commentsCount:{"$size":{"$filter":{"input":"$comments","as":"item","cond":{"$gt":["$$item.createdAt",ISODate("2022-09-03T00:00:00Z")]}}}}}}])