I want to count how often a unique value occurs. I have multiple arrays with objects like:
{“value”:”a”,”begin”:0,”end”:12}
but I only need the “value” part of the object so I projected only the values so the result of my projection looks like this but with multiple arrays:
{“values”:[{“value”:”a”},{“value”:”b”},{“value”:”b”}]}
My goal is to get a result array with all different values and how often they occurred in all multiple arrays:
[{“value”:”a”,”count”:1},{“value”:”b”,”count”:2}]
$unwindand$groupwith{$sum:1}{$unwind: "$values"}. Please provide few sample documents and I'll show you{ "values": [ "value": "a", "value": "b", "value": "c", "value": "a", "value": "b", "value": "c" ] }{ "values": [ "value": "a", "value": "b", "value": "d", "value": "g", "value": "d", "value": "c" ] }And as result i need:{ {"value": "a", "count": 3}, {"value": "b", "count": 3}, {"value": "c", "count": 3}, {"value": "d", "count": 2}, {"value": "g", "count": 1}, }