title: Mongoose Populate return empty array with joining and generating children from other table
body: <p>I have looked at all of the cases on StackOverflow but I could not fix this error:
  You can find the whole code here :
  <a href="https://codesandbox.io/s/musing-http-n4fcs?file=/src/index.js:454-1179" rel="nofollow noreferrer">Link to SandBox</a>
  I have 2 collections: &quot;pars&quot; for parents and &quot;chil&quot; for children</p>
  <p><strong>pars:</strong></p>
  <p><a href="https://i.stack.imgur.com/glgkT.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/glgkT.jpg" alt="Pars Collection" /></a></p>
  <pre><code>[{
    &quot;_id&quot;: {
      &quot;$oid&quot;: &quot;607091fa48ea8376b9398ba7&quot;
    },
    &quot;name&quot;: &quot;ParA&quot;
  },{
    &quot;_id&quot;: {
      &quot;$oid&quot;: &quot;6070920748ea8376b9398ba8&quot;
    },
    &quot;name&quot;: &quot;ParB&quot;
  }]
  </code></pre>
  <p><strong>chil:</strong></p>
  <p><a href="https://i.stack.imgur.com/4gBZW.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/4gBZW.jpg" alt="Chils Collection" /></a></p>
  <pre><code>[{
    &quot;_id&quot;: {
      &quot;$oid&quot;: &quot;6070921648ea8376b9398ba9&quot;
    },
    &quot;name&quot;: &quot;Chil1&quot;,
    &quot;parRef&quot;: {
      &quot;$ref&quot;: &quot;chils&quot;,
      &quot;$id&quot;: {
        &quot;$oid&quot;: &quot;6070920748ea8376b9398ba8&quot;
      }
    },
    &quot;parId&quot;: &quot;6070920748ea8376b9398ba8&quot;
  },{
    &quot;_id&quot;: {
      &quot;$oid&quot;: &quot;6070922648ea8376b9398baa&quot;
    },
    &quot;name&quot;: &quot;Chil2&quot;,
    &quot;parRef&quot;: {
      &quot;$ref&quot;: &quot;chils&quot;,
      &quot;$id&quot;: {
        &quot;$oid&quot;: &quot;607091fa48ea8376b9398ba7&quot;
      }
    },
    &quot;parId&quot;: &quot;607091fa48ea8376b9398ba7&quot;
  },{
    &quot;_id&quot;: {
      &quot;$oid&quot;: &quot;6070923348ea8376b9398bab&quot;
    },
    &quot;name&quot;: &quot;Chil3&quot;,
    &quot;parRef&quot;: {
      &quot;$ref&quot;: &quot;chils&quot;,
      &quot;$id&quot;: {
        &quot;$oid&quot;: &quot;607091fa48ea8376b9398ba7&quot;
      }
    },
    &quot;parId&quot;: &quot;607091fa48ea8376b9398ba7&quot;
  }]
  </code></pre>
  <p>I am using <strong>populate</strong> with <strong>mongoose</strong> but it returns an empty array
  <strong>Code</strong></p>
  <pre><code>const Schema = mongoose.Schema;
  const getParChil = async () =&gt; {
    const schemaPar = new Schema(
      {
        _id: Schema.Types.ObjectId,
        name: String,
        chils: [
          {
            type: Schema.Types.ObjectId,
            ref: &quot;modelChil&quot;
          }
        ]
      },
      { collection: &quot;pars&quot; }
    );
  
    const schemaChil = new Schema(
      {
        _id: Schema.Types.ObjectId,
        name: String,
        parId: { type: Schema.Types.ObjectId, ref: &quot;modelPar&quot; }
      },
      { collection: &quot;chils&quot; }
    );
  
    const modelChil = mongoose.model(&quot;modelChil&quot;, schemaChil);
    const modelPar = mongoose.model(&quot;modelPar&quot;, schemaPar);
  
    const res = await modelPar.find({}).populate(&quot;chil&quot;);
    console.log(&quot;result&quot;, res);
  };
  
  getParChil();
  </code></pre>
  <p><strong>response:</strong></p>
  <pre><code>[
    { chils: [], _id: 607091fa48ea8376b9398ba7, name: 'ParA' },
    { chils: [], _id: 6070920748ea8376b9398ba8, name: 'ParB' }
  ]
  </code></pre>
  <p>Please advise. I would like to join these two tables and get the result like this:
  <strong>expected behaviour</strong></p>
  <pre><code>[
  {
  _id: 607091fa48ea8376b9398ba7, 
  name:&quot;ParA&quot;,
  chils:[{&quot;name&quot;:&quot;Chil2&quot;},{&quot;name&quot;:&quot;Chil3&quot;}]
  },
  {
  _id: 6070920748ea8376b9398ba8,
  name:&quot;ParB&quot;,
  chils:[{&quot;name&quot;:&quot;Chil1&quot;}]
  }
  ]
  </code></pre>