1 Answers

productId in the wishList is a String, while the _id field in product is an ObjectId.

You can change the type of the productId in the wishList or you can use $lookup with let and pipeline to project the _id in product as a String value before comparing it to wishList.productId, like this:

{
    "$lookup":
    {
        "from": "products",
        "let":
        {
            "productId": "$wishList.productId"
        },
        "pipeline":
        [
            {
                "$addFields":
                {
                    "idAsString":
                    {
                        "$toString": "$_id"
                    }
                }
            },
            {
                "$match":
                {
                    "$expr":
                    {
                        "$eq":
                        [
                            "$idAsString",
                            "$$productId"
                        ]
                    }
                }
            }
        ]
    }
}

I haven't tested the query, since you didn't provide an easy way to reproduce the error, as mentioned by toyota Supra in the comment to your question, but it should be something along these lines.

Related