I have the following document structure
[
{
"tag": "abc",
"created_at": 2020-02-05T14:20:52.907+00:00
"likes": 12,
"comments": 3
},
{
"tag": "abc",
"created_at": 2020-02-04T14:20:52.907+00:00
"likes": 10,
"comments": 1
}
{
"tag": "abc",
"created_at": 2020-01-04T14:21:52.907+00:00
"likes": 12,
"comments": 3
},
{
"tag": "abc",
"created_at": 2020-01-04T14:22:52.907+00:00
"likes": 2,
"comments": 1
}
]
First, I want to group my documents based on tag value and then on created_at field to get something like this.
[
{
"tag_name": "abc",
"day_wise": [
{
"dayMonthYear": "2020-01-04",
"comments": 4,
"likes": 14
},
{
"dayMonthYear": "2020-02-04",
"comments": 1,
"likes": 10
},
{
"dayMonthYear": "2020-02-05",
"comments": 3,
"likes": 12
},
],
"month_wise": [
{
"monthYear": "2020-04",
"comments": 5,
"likes": 24
},
{
"monthYear": "2020-05",
"comments": 3,
"likes": 12
},
],
}
]
There can be multiple tags so need to group them accordingly. Can anyone please suggest what aggregation query can be applied to achieve this result.
month_wise. It should be2020-01&2020-02instead of2020-04&2020-05.