I have collection of documents that are output from aggregation and they were grouped by name. Each object should be accessed by name property and its unique. Each of them contain values, I want to get count of each value in their array without losing uniqueness of name property.
{
name: "Foo",
values: ["FOO", "BAR", "FOO"]
},
{
name: "Bar",
values: ["BAZ", "BAR", "BAR"]
},
{
name: "Baz",
values: ["BAZ", "BAZ", "BAZ"]
}
I want to turn their array of strings into array of objects. Each of these objects has value that represents one of string values and count of how often was that value repeated in array of strings as shown below:
{
name: "Foo",
values: [
val: "FOO", count: 2,
val: "BAR", count: 1
]
},
{
name: "Bar",
values: [
val: "BAR", count: 2,
val: "BAZ", count: 1
]
},
{
name: "Baz",
values: [
val: "BAZ", count: 3
]
}