title: MongoDB : Push or merge one lookup's result in other lookup's result
body: <p>I have 3 collection namely <code>constants</code>, <code>activities</code>, <code>applications</code> with mentioned properties.</p>
  <p>Now, querying <code>constants</code> collection with <code>activities</code> and <code>activities</code> with <code>applications</code> with matching Id's. I am getting correct results. But now <code>activity_types</code> are shown at per data level.</p>
  <p>But expecting the output should be at per <code>item</code> level inside <code>data</code> whichever is matching with item. Because <code>activities</code> are matching for Item and it should be shown in per item level not at data level. I tried with <code>$push</code> and <code>$group</code> but not getting expected results.</p>
  <p>Constants</p>
  <pre><code>{
      _id: id
      value : {
          categories: [
              {
                  id: 001,
                  title: &quot;test 1&quot;
              },
              {
                  id: 002,
                  title: &quot;test 2&quot;
              },
              {
                  id: 003,
                  title: &quot;test 3&quot;
              }
          ]
      }
  }
  </code></pre>
  <p>Activity</p>
  <pre><code>{
      propert1: &quot;&quot;,
      propert2: &quot;&quot;,
      config: {
          agenda_item_category_ids: [ObjectId(001), ObjectId(002)]
      },
      activity_type_id: ObjectId(123)
  
  }
  {
      propert1: &quot;&quot;,
      propert2: &quot;&quot;,
      activity_type_id: ObjectId(456)
      config: {
          agenda_item_category_ids: [ObjectId(002)]
      }
  
  }
  </code></pre>
  <p>applications</p>
  <pre><code>{
      _id: ObjectId(123),
      prop1: &quot;&quot;,
      prop2: &quot;&quot;
  }
  {
      _id: ObjectId(456),
      prop1: &quot;&quot;,
      prop2: &quot;&quot;
  }
  </code></pre>
  <p>Current query</p>
  <pre><code>const results = await Constants.aggregate([
      {
          $match: query,
      },
      {
          $unwind: {
              path: '$value.categories',
              preserveNullAndEmptyArrays: true,
          },
      },
      {
          $lookup: {
              from: 'activity',
              localField: 'value.categories.id',
              foreignField: 'config.agenda_item_category_ids',
              as: 'data',
          },
      },
      {
          $lookup: {
              from: 'applications',
              localField: 'items.activity_type_id',
              foreignField: '_id',
              as: 'activity_type',
          },
      },
      {
          $project: {
              _id: 0,
              category_id: '$value.categories.id',
              title: '$value.categories.title',
              description: '$value.categories.description',
              icon_src: '$value.categories.icon_src',
              data: 1,
              activity_type: 1,
          },
      },
  ]);
  </code></pre>
  <p>Current output</p>
  <pre><code>[
      {
          data: [
              {item1},
              {item2}
          ],
          activity_type,
          title
          _id
      },
      {
          data: [
              {item1},
              {item2}
          ],
          activity_type,
          title
          _id
      }
  ]
  </code></pre>
  <p>Expected output</p>
  <pre><code>[
      {
          data: [
              {
                  item1,
                  activity_type
              },
              {
                  item2,
                  activity_type
              }
          ],
          title
          _id
      },
  ]
  </code></pre>
  <p>Tried method</p>
  <pre><code>{
    &quot;_id&quot;: &quot;$_id&quot;,
    &quot;activity_type&quot;: {
      &quot;$push&quot;: &quot;$activity_type&quot;
    }
  }
  </code></pre>