'Fetched Matched Array data in MongoDB

I have an MongoDB object like:

{
  "user" : ObjectId("60e5f88159292f575c0ca17f"),
  "questions" :[
     {
       question 'aaaaaaa',
       id :'1'
     },
     {  
       question 'bbbbbbb',
       id :'2'
     },
     {
       question 'ccccccc',
       id :'3'
     }
   ]
}

I want to pass an array of questions id ['1', '3'] and user object id. I want to fetch the question which matches the questions id and user.

My expected output should look like this:

{
  "user" : ObjectId("60e5f88159292f575c0ca17f"),
  "questions" :[
     {
       question 'aaaaaaa',
       id :'1'
     },
     {
       question 'ccccccc',
       id :'3'
     }
   ]
}

How can I do this?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source