Reputation: 5785
Below is my mongodb structure
[
{
"_id": "com.android.angrybirds",
"rating": [
{
"user": "BBE74610BEE1A92784FDB",
"value": "1"
},
{
"user": "BBE74610BEE1A92784F",
"value": "5"
},
{
"user": "BBE74610BEE1A9784F",
"value": "5"
}
]
}
]
I want to group and count the unique ratings. I tried to use aggregate, group but it didn't work.
Expected output
[
{
"_id": "com.avatarrom.angrybirds",
"rating": [
{
"1": 1,
"5": 2
}
]
}
]
Upvotes: 0
Views: 287
Reputation: 5979
Like @RickyA said, your aggregation query would be interesting. What you need is the aggregate function in combination with the group operator. This post has a nice sample how you can do that.
Upvotes: 1