I have the following collections in my database:
{
"username" : "John",
"shopping_cart" : {
"coffee" : 2,
"chocolate" : 3
(...will have about 50 different products that can be added to the shopping cart)
},
}
Is there a way to aggregate all items that a user had added in the shopping cart and get a total sum of the entire quantity of the cart? Something like this.
db.items.aggregate([
{$group: {
_id: null,
prices: {$sum: "$all_items_in_shopping_cart}
}}
])