Just stepping into the world of mongodb, my query skills are still a work in progress. Let's dive straight into the problem at hand. Here is an example document for each user:
{
id:"14198959",
user_name:"kikStart2X"
friends:[
{
friend_id:"1419897878",
friend_name:"nitpick",
profile_picture:"some image data",
},
{
friend_id:"14198848418",
friend_name:"applePie",
profile_picture:"some image data",
}, //etc
],
games:[
{
game_id:"1" ,
game_name:"Bunny Hop"
},
{
game_id:"2" ,
game_name:"Racing cars",
},
],
}
Now, all the documents in the collection follow the same structure.
1) The friends array represents the users who are my friends.
2) The games array represents the games I have played.
Each of my friends would have a similar document structure with their own list of games they have played.
What I am aiming for is to identify and list the most common games between me and my friends, in any order specified - ascending, descending or otherwise.
The desired result should appear as follows:
{
result:
[
{
game_id:"1" ,
game_name:"Bunny Hop",
friends:
[
{
friend_id:"1419897878",
friend_name:"nitpick",
profile_picture:"some image data",
},
{
friend_id:"14198848418",
friend_name:"applePie",
profile_picture:"some image data",
},
]
},
{
game_id:"2" ,
game_name:"Racing cars",
friends:
[
{
friend_id:"71615343",
friend_name:"samuel",
profile_picture:"some image data",
},
]
}
]
}
This may pose a challenging task, but I lack the knowledge on how to approach it even after hours of scouring the internet for solutions. Thank you in advance to all MongoDB experts out there!