Im using mongoDB and I need to find a users most popular entries. Im rather confused about how to do this. I believe I will need to use the aggregate method however im not too sure how. This is the user data
{
"_id": ObjectId("58d26c3dd60bd36f40fa0498"),
"user_id": ObjectId("587cd30bd338b90a6c18e58f"),
"calories": 2000,
"date": 20170222,
"snacks": [
{
"nutrients": {
"protein": 8.7,
"carbs": 53.5,
"fat": 34.8
},
"servings": 21,
"calories": 495,
"name": "Kinder Chocolate"
},
{
"nutrients": {
"protein": 7.5,
"carbs": 56.5,
"fat": 10.5
},
"servings": 23.8,
"calories": 526,
"name": "Dairy milk"
}
],
"dinner": [ ],
"lunch": [ ],
"breakfast": [ ]
}
Essentially I need to get the most popular items, for example if the user has added Kinder chocolate more than anything else it will be top of the list:
1."Kinder Chocolate"
2."Dairy milk"
3."Coca Cola"
Any help would be greatly appreciated.