Trying to identify the top body locations using a dataset structured like this... the dataset consists of an array of objects, each containing an array called bodyLocations which I need to analyze to determine the most frequently appearing locations such as r-ovary, l-ovary etc.
My current approach involves concatenating all body locations arrays together and then counting them. However, I have a feeling there might be a more efficient way to accomplish this. Should I delegate this task to MongoDB, where the data originates from, or continue handling it on my server? Any suggestions on the best strategy for tackling this issue?
Data snapshot for the week: [
{
bodyLocations: [ 'r-ovary', 'l-ovary', 'l-leg', 'r-leg', 'head' ],
typePain: [ 'aching', 'fatigue' ],
_id: 6074d376215c0c033aa41aef,
postedBy: 6060ca6b8dbe9d02e4ad1063,
created: '2021-04-12',
symptomDate: 2021-04-12T00:00:00.000Z,
painlevel: 6,
__v: 0
},
{
bodyLocations: [ 'r-ovary', 'uterus' ],
typePain: [ 'fatigue', 'twisting', 'radiating' ],
_id: 6074dd89ebabd8034831786a,
postedBy: 6060ca6b8dbe9d02e4ad1063,
created: '2021-04-12',
symptomDate: 2021-04-12T00:00:00.000Z,
painlevel: 9,
__v: 0
}