Here see this Collection here have a record with createdAt with 14Feb and one with 16Feb, Now querying an aggregation on the collection such as I want to add an document of 15Feb as it was missing in collection with viewCount and clickCount as 0.
So looking for some way to add missing date record/document in aggreagation pipeline.
Pipeline I have
[
{
$group: {
_id: {
$dateToString: { format: "%Y-%m-%d", date: "$createdAt" },
},
viewCount: { $sum: "$viewCount" },
clickCount: { $sum: "$clickCount" },
},
},
{ $sort: { _id: 1 } },
{
$group: {
_id: null,
data: {
$push: {
k: "$_id",
v: { viewCount: "$viewCount", clickCount: "$clickCount" },
},
},
},
},
{
$project: {
_id: 0,
data: { $arrayToObject: "$data" },
},
},
]```
I looking for some operator in mongo or some way to do this
By combination of both javascript and aggregation pipeline, you can achieve the desired result.