title: MongoDB lookup in multi label nested array
body: <p>I am very new in MongoDB. I am trying to make lookup in multi label nested array. My data is looks like bellow.</p>
  <pre class="lang-json prettyprint-override"><code>[
      {
          &quot;_id&quot;: &quot;621eedae92979fd8f0e9451d&quot;,
          &quot;name&quot;: &quot;Pallab Koley&quot;,
          &quot;shifts&quot;: {
              &quot;_id&quot;: &quot;62636b9fcbda6d2b17f5cae0&quot;,
              &quot;month&quot;: &quot;2022-05&quot;,
              &quot;shift&quot;: [
                  {
                      &quot;date&quot;: &quot;2022-05-01&quot;,
                      &quot;shiftId&quot;: &quot;622bb0f4b88dc92e3c2cac56&quot;
                  }
              ]
          }
      },
      {
          &quot;_id&quot;: &quot;62626a7446ba9a911a623b37&quot;,
          &quot;name&quot;: &quot;Pinki Das&quot;,
          &quot;shifts&quot;: {
              &quot;_id&quot;: &quot;62636ba4cbda6d2b17f5cae1&quot;,
              &quot;month&quot;: &quot;2022-05&quot;,
              &quot;shift&quot;: [
                  {
                      &quot;date&quot;: &quot;2022-05-01&quot;,
                      &quot;shiftId&quot;: &quot;622bb0f4b88dc92e3c2cac56&quot;
                  }
              ]
          }
      }
  ]
  </code></pre>
  <p>And I am trying to run lookup like bellow.</p>
  <pre class="lang-js prettyprint-override"><code>{
      &quot;$lookup&quot;: {
        &quot;from&quot;: &quot;shifts&quot;,
        &quot;localField&quot;: &quot;shifts.shift.shiftId&quot;,
        &quot;foreignField&quot;: &quot;_id&quot;,
        &quot;as&quot;: &quot;shifts.shift.shiftId&quot;
      }
    }
  </code></pre>
  <p>I am getting the result.</p>
  <pre class="lang-json prettyprint-override"><code>[
      {
          &quot;_id&quot;: &quot;621eedae92979fd8f0e9451d&quot;,
          &quot;name&quot;: &quot;Pallab Koley&quot;,
          &quot;shifts&quot;: {
              &quot;_id&quot;: &quot;62636b9fcbda6d2b17f5cae0&quot;,
              &quot;month&quot;: &quot;2022-05&quot;,
              &quot;shift&quot;: {
                  &quot;shiftId&quot;: [
                      {
                          &quot;_id&quot;: &quot;622bb0f4b88dc92e3c2cac56&quot;,
                          &quot;name&quot;: &quot;Day&quot;
                      }
                  ]
              }
          }
      },
      {
          &quot;_id&quot;: &quot;62626a7446ba9a911a623b37&quot;,
          &quot;name&quot;: &quot;Pinki Das&quot;,
          &quot;shifts&quot;: {
              &quot;_id&quot;: &quot;62636ba4cbda6d2b17f5cae1&quot;,
              &quot;month&quot;: &quot;2022-05&quot;,
              &quot;shift&quot;: {
                  &quot;shiftId&quot;: [
                      {
                          &quot;_id&quot;: &quot;622bb0f4b88dc92e3c2cac56&quot;,
                          &quot;name&quot;: &quot;Day&quot;
                      }
                  ]
              }
          }
      }
  ]
  </code></pre>
  <p>But my expectation data should looks like bellow.</p>
  <pre class="lang-json prettyprint-override"><code>[
      {
          &quot;_id&quot;: &quot;621eedae92979fd8f0e9451d&quot;,
          &quot;name&quot;: &quot;Pallab Koley&quot;,
          &quot;shifts&quot;: {
              &quot;_id&quot;: &quot;62636b9fcbda6d2b17f5cae0&quot;,
              &quot;month&quot;: &quot;2022-05&quot;,
              &quot;shift&quot;: [
                  {
                      &quot;date&quot;: &quot;2022-05-01&quot;,
                      &quot;shiftId&quot;: {
                          &quot;_id&quot;: &quot;622bb0f4b88dc92e3c2cac56&quot;,
                          &quot;name&quot;: &quot;Day&quot;
                      }
                  }
              ]
          }
      },
      {
          &quot;_id&quot;: &quot;62626a7446ba9a911a623b37&quot;,
          &quot;name&quot;: &quot;Pinki Das&quot;,
          &quot;shifts&quot;: {
              &quot;_id&quot;: &quot;62636ba4cbda6d2b17f5cae1&quot;,
              &quot;month&quot;: &quot;2022-05&quot;,
              &quot;shift&quot;: [
                  {
                      &quot;date&quot;: &quot;2022-05-01&quot;,
                      &quot;shiftId&quot;: {
                          &quot;_id&quot;: &quot;622bb0f4b88dc92e3c2cac56&quot;,
                          &quot;name&quot;: &quot;Day&quot;
                      }
                  }
              ]
          }
      }
  ]
  </code></pre>
  <p>Here is <code>date</code> field under <code>shifts.shift</code> is missing. <code>shiftId</code> is replacing all the field under shift array. Please help me out.
  <a href="https://mongoplayground.net/p/t3YxW_gH5ls" rel="nofollow noreferrer">mongoplayground</a></p>