How to convert string to objectId in LocalField for $lookup Mongodb : <p>I want to add join collections using <code>$lookup</code> in mongodb. I am trying as below</p>

<pre><code>{
 $lookup:{
   from:"User",
   localField:"assignedId",
   foreignField:"_id",
   as:"dataa"}
}
</code></pre>

<p>Now I have two collections  </p>

<p><strong>User</strong> contains <code>objectid</code> of users like  <code>"_id" : ObjectId("56ab6663d69d2d1100c074db"),</code></p>

<p>and  <strong>Tasks</strong> where it contains <code>assignedId</code> as a <code>string</code> <code>"assignedId":"56ab6663d69d2d1100c074db"</code></p>

<p>Now, when applying $lookup in both collection its not working because Id's are not matching.</p>

<p>For that I googled it and found a solution that to include</p>

<p><code>{ $project: { assignedId: {$toObjectId: "$assignedId"} }}</code> </p>

<p>but this solution is not working for me, Its throwing an error:</p>

<pre><code>assert: command failed: { "ok" : 0, "errmsg" : "invalid operator '$toObjectId'", "code" : 15999 } : aggregate failed
</code></pre>

<p>Please help me how can I resolve this issue.</p>

<p>Thanks</p>
