Here\'s my MongoDB collection:
{
\"_id\" : ObjectId(\"515d8f53175b8ecb053425c2\"),
\"category\" : \"Batteries\",
\"products\" : [
{
I know it is an old question and you've solved it several years ago! But there is a small problem in the answer you've marked as correct and it may not suitable for all cases. The $unwind is an expensive operator and may affect latency and memory consumption for large datasets. I think the $reduce operator is more performant in this case.