How to add array to each object inside array

Viewed 13

I would like to query two collections and desired output should join 'Answer' collection with 'Question' collection where 'Answer' array will be included in 'Question' array of objects. So far I tried with $group but stuck. Any help appreciated!

   Code:

  $lookup: {from: 'AnswerSet',

    localField: 'QuestionId',

    foreignField: 'QuestionId',

    as: 'QuestionAnswer'

    },

$group: {_id:0,

QuestionAnswer: { 

 $addToSet: {QuestionText1: "$QuestionText1", QuestionText2: "$QuestionText2", 

 QuestionText3: "$QuestionText3", AnswerSet: "$AnswerSet"

     }




 
 
0 Answers
Related