title: $ lookup on array of mongodb objects
body: <p>There is a collection of books in which data is stored in this format, my task is to get comments and information about the user who left the comment through a search. I managed to replace id with information with a comment and then replace user id with their information. But my solution partially works because I can't get information about users through let and pipeline in search.</p>
  <p>Sample data</p>
  <pre><code>&quot;book&quot;:{
      _id:...,
      ...,
      //Array&lt;String&gt;
      comments:[
          &quot;609331be9eaf660870f7115c&quot;,
          &quot;609331be9eaf660870f7115d&quot;,
          &quot;609331be9eaf660870f7115e&quot;,
          &quot;609331be9eaf660870f7115f&quot;,
          &quot;612639cb6fd55ca429d723bd&quot;
      ]
  }
  </code></pre>
  <p>First iteration</p>
  <pre><code>{ $lookup: {
      from: 'comments',
      let: {id: &quot;$_id&quot;},
      pipeline: [
          {$match:
              {$expr: {
                  $or:[
                          {$eq: [&quot;$_bookId&quot;, &quot;$$id&quot;]}, //If ObjectId 
                          {$eq: [&quot;$_bookId&quot;, { $toString: &quot;$$id&quot; }]} //If String
                      ]
                  }
              }
          }
      ],
      as: 'comments'
  }}
  </code></pre>
  <p>Result after the first iteration:</p>
  <pre><code>&quot;book&quot;:{
      //Array&lt;String&gt;
      _id:...,
      ...,
      //Array&lt;Object&gt;
      comments:[
          {
              &quot;_id&quot;: &quot;609331be9eaf660870f7115c&quot;,
              &quot;_user&quot;: &quot;608b8e66c339f71634642f68&quot;,
              &quot;text&quot;: &quot;Some text&quot;
          },
          ...
      ]
  }
  </code></pre>
  <p>Second iteration without let and pipeline</p>
  <pre><code>{ $lookup: {
      from: 'users',
      localField:'comments._user',
      foreignField:'_id',
      as: 'comments_user'
  }}
  </code></pre>
  <p>Unsuccessful attempts:</p>
  <pre><code>{ $lookup: {
      from: 'users',
      let: {id_temp: &quot;$сomments&quot;}, //&quot;$сomments._user&quot;
      pipeline: [
          {$match:
          {$expr: {
              $or:[
                  {$eq: [&quot;$_id&quot;, &quot;$$id_temp&quot;]},
                  {$eq: [&quot;$_id&quot;, { $toString: &quot;$$id_temp&quot; }]}
              ]}
          }}
      ],
      as: 'comments_user'
  }}
  </code></pre>