I want to add a collection of collections using $lookup
in mongodb. I try as below
{ $lookup:{ from:"User", localField:"assignedId", foreignField:"_id", as:"dataa"} }
I now have two collections
The user contains the objectid
of users such as "_id" : ObjectId("56ab6663d69d2d1100c074db"),
and Tasks , where it contains assignedId
as string
"assignedId":"56ab6663d69d2d1100c074db"
Now, applying $ lookup in both assemblies, it does not work, because Id does not match.
For this, I googled and found a solution that includes
{ $project: { assignedId: {$toObjectId: "$assignedId"} }}
but this solution does not work for me, its error:
assert: command failed: { "ok" : 0, "errmsg" : "invalid operator '$toObjectId'", "code" : 15999 } : aggregate failed
Please help me how can I solve this problem.
thanks
source share