title: How to return specific document from different collection by a specific field inside aggregation
body: <p>I want to populate just those documents from <code>users</code> collection where <code>users._id</code> is equal to <code>levelOne.assignedPeople</code> ids. This will arrive as an array.</p>
  <p>I am using this query,</p>
  <pre><code>db.parentepics.aggregate([
  {
      $match: {
        ideaId: &quot;616bffd81a9c715679374b19&quot;,
        isDeleted: false,
        isHidden: false,
        isRemovedByOwner: false,
      },
  },
  {
      $lookup: {
        from: &quot;childtasklevelones&quot;,
        localField: &quot;_id&quot;,
        foreignField: &quot;parentEpicId&quot;,
        as: &quot;level_1&quot;,
      },
    },
    {
      $match: {
        &quot;level_1.assignedPeople&quot;: ObjectId('616c00001a9c715679374b1b'),
      },
    },
    {
      $project: {
        _id: 1,
        epicName: 1,
        epicDescription: 1,
        epicPriority: 1,
        startsFrom: 1,
        endsAt: 1,
        levelOne: &quot;$level_1&quot;,
      },
    }
  ])
  </code></pre>
  <p>Which produces some output looks like this,</p>
  <pre><code>{
      &quot;_id&quot; : ObjectId(&quot;616c099e1a9c715679374b7c&quot;),
      &quot;epicName&quot; : &quot;Marketing&quot;,
      &quot;epicDescription&quot; : &quot;Marketing data&quot;,
      &quot;epicPriority&quot; : &quot;1&quot;,
      &quot;startsFrom&quot; : ISODate(&quot;2021-10-15T14:36:31.387+05:30&quot;),
      &quot;endsAt&quot; : ISODate(&quot;2021-10-30T14:36:31.387+05:30&quot;),
      &quot;levelOne&quot; : [
          {
              &quot;_id&quot; : ObjectId(&quot;616db350123f016231912954&quot;),
              &quot;currentStatus&quot; : &quot;pending&quot;,
              &quot;assignedPeople&quot; : [
                  ObjectId(&quot;616c00001a9c715679374b1b&quot;)
              ],
              &quot;isRemovedByOwner&quot; : false,
              &quot;highlightColorPreference&quot; : &quot;yellow&quot;,
              &quot;isHidden&quot; : false,
              &quot;isDeleted&quot; : false,
              &quot;taskName&quot; : &quot;Marketing&quot;,
              &quot;taskDescription&quot; : &quot;Marketing data&quot;,
              &quot;taskPriority&quot; : &quot;1&quot;,
              &quot;startsFrom&quot; : ISODate(&quot;2021-10-15T14:36:31.387+05:30&quot;),
              &quot;endsAt&quot; : ISODate(&quot;2021-10-30T14:36:31.387+05:30&quot;),
              &quot;createdBy&quot; : ObjectId(&quot;616bffd81a9c715679374b18&quot;),
              &quot;parentEpicId&quot; : ObjectId(&quot;616c099e1a9c715679374b7c&quot;),
              &quot;taskNameToLower&quot; : &quot;marketing&quot;,
              &quot;createdAt&quot; : ISODate(&quot;2021-10-18T23:18:00.464+05:30&quot;),
              &quot;updatedAt&quot; : ISODate(&quot;2021-10-18T23:18:00.464+05:30&quot;),
              &quot;__v&quot; : 0
          }
      ]
  }
  </code></pre>
  <p>Now I just need to populate users from users collection where <code>users._id</code> is equal to <code>levelOne.assignedPeople</code>.</p>
  <p>I sort, I need the array of users in place of these <code>levelOne.assignedPeople</code> ids.</p>
  <p>Please help me to modify the query.</p>
  <p>Thanks</p>