I'm new with mongo and still trying to drift my head away from the mySQL methodology and dive it into mongo, so a few things are still blur on how i'm suppose to do and i was hopping you guys could shed me some light.
Let me explain the problem. I'm using nodeJS and the mongodb native.
Say i have a collection of users (i've used simpler _id just to illustrate, i know its an objectID, but consider just for the sake of the example)
{
_id: 1,
name: 'John',
likes: ['2','3','4']
},
{
_id: 2,
name: 'Michelle'
likes: ['1','4']
},
{
name: 'Sabrina'
_id: 3,
likes: []
},
{
name: 'Simone'
_id: 4,
likes: ['1','2', '3']
}
note that John liked Michell, Sabrina, and Simone, that Michelle liked John and Simone, Sabrina didn't like anyone, and Simone liked John, Michelle and Sabrina.
How do i run a query for John to find out who also liked him back based on his array of likes? I need something that would return Michelle if id = 1, or returns John and Michelle if id = 4. Only the ones that the id i'm fetching is in the other users like.
let me try to simplify.
I need to fetch John and go through all his likes and check id 2 likes me back? Yes id 3 likes me back? No
return [John];
or fetch Simone and go through all her likes and check id 1 likes me back? Yes id 2 likes me back? Yes id 3 likes me back? No
return [John, Michelle]
Any help would be appreciated :) thanks