Hi, I have collection with schema something like below
page_id | even_type
even_type - has two values 1. load, 2.click
I’m trying to aggregate it like
page | total_impression | total_clicks
I tried following, but getting same value in both columns
db.metrics.aggregate([
{
$group: {
_id : {
page_id:'$page_id',
event_type:'load'
}, total_impressions:{$sum :1},
_id : {
page_id:'$page_id',
event_type:'click'
}, total_clicks:{$sum :1}
}
},
{
$project : {
page_id:'$_id.page_id',
total_impressions : '$total_impressions',
total_clicks : '$total_clicks',
_id : 0
}
}, { $out : "metrics_results" }
])
Can you please help me?