0

I have a data set with this structure:

{
"price" : 48.00"
"year" : "2008",
"model" : "something",
"manufacturer" : "ACME",
"productgroup" : "3629",
}

I want to count how many items a manufacturer has per product group, so the output for the above sample data, would be:

{productgroup:"3629", manufacturer: "ACME", count: 34 }

I do everything in mongo shell/robomongo and i am glad for every hint how to tackle this.

BatScream
  • 19,260
  • 4
  • 52
  • 68
lolops
  • 97
  • 1
  • 11

1 Answers1

2

Try the below query.

db.collection.aggregate(
{$group: 
    {
     "_id": {"pr": "$productgroup", "mn": "$manufacturer"}, 
     "count": {$sum:1}
    }
})

The idea is to have both the fields specified in the _id field of group.

Lalit Agarwal
  • 2,354
  • 1
  • 14
  • 18
  • thanks lalit, and thanks for the link "Mongodb Aggregation Framework | Group over multiple values?", but the link really doesnt help me as i don't see how to solve my problem with the information given. – lolops Apr 29 '15 at 21:29