1

i have a collection called 'users' and inside that collection their is a field called friends which is an array.. it includes an user id.

{ 
  _id: 1
  username: xxx
  friends: [
     {
        userId: 2
     }
  ]
},
{
  _id: 2
  username: yyy
  friends: [
     {
        userId: 1
     }
  ]
}

i want to display user 2 data as friend of user 1 like this

friends: [
   {
     userId: 2
     username: yyy
   }
]

1st select user where _id = 1 then for all userId in friends output user data that matches userId and _id

Arippe
  • 21
  • 1
  • 8

0 Answers0