Given data like
[
{ _id:1, data:["abc", "def", "hij", "klm", "nop"]},
{ _id:2, data:["abc", "def", "hij"]},
{ _id:3, data:["abc", "hij"]},
{ _id:4, data:["abc", "def", "hij", "klm", "nop"]},
{ _id:5, data:["def", "hij", "klm"]},
]
I am trying to get a query result like
[
{ "abc": 4 },
{ "def": 4 },
{ "hij": 5 },
{ "klm": 3 },
{ "nop": 2 },
]
where the number is the count of each data property array string value.
I have been working on it from an aggregate pipeline approach, but it seems like there should be an easier way.
javascript? would you accept an answer using javascript's array methods?Javascriptside, but I believe you want it to comes already processed toJavascript. Anyway, I suggest to add what you have tried to far...