Lookup string to object id

I have an issue with the lookup field using in my charts. I need to pull one collection (customer) to another collection(program). CustomerId(object type in customer) is not the same in Program(it is string type in Program collection). I cannot change the types in the collection.
I followed some of the previous posts and did some changes in my aggregation pipeline(managed charts view in program collection).

$lookup: {
from: “customer”,
let: {customerId: “$customerId”},
{$match: {
{$eq:[“$_id”:{$toObjectId: “$customerId”}]}
as: “cid”

Not sure where I am doing it wrong. Page is not even letting me test my pipeline or save it. Is there anything wrong in my code?
Thanks in advance.

If you look at the examples in the $lookup documentation you will see that variables defined with let: needs to use 2 $ signs. So I would try replacing $customerId in your $toObjectId with $$customerId.

What do you mean by:

Sure, will try. Thank you for your response.

1 Like