I'm struggling with a MongoDb query.
I have a query that makes group and count some fields, for example:
field_name | count
___________________
field1 | 10
field2 | 20
field3 | 30
And also I would like to add total count at the end to make it look like this:
field_name | count
___________________
field1 | 10
field2 | 20
field3 | 30
total | 60
I understand how I can achieve it in SQL (either UNION or ROLLUP) although I can't find a way to do it in Mongo.
Here's my query just in case:
db.subscriptions.aggregate([
{$match: {isExpired: false}},
{$group: {_id: '$productId', count: {$sum: 1}}}
])