Reputation: 567
I am using MongoDB aggregate function and after $match and $group I have this array of data
[ { _id: { item: 'AAA' }, total: 66 },
{ _id: { item: 'BBB' }, total: 3 } ]
Is there any way to use $project to turn the final result into
[ {AAA: 66}, {BBB: 3} ]
And to make it more fun, let's say there is {CCC: 0} in the results as well, how can we filter and remove element CCC if it have value equal to 0?
Upvotes: 1
Views: 134