regexMatch fails with a variable string

const searchField = "$data.product";

But If I try to use concatenation and add a variable name const searchField = "$data." + key; then it fails with the error:

MongoServerError: PlanExecutor error during aggregation:: caused by:: $regexMatch needs ‘input’ to be of type string

I have tried using template format but it also does not work $data.${key}

What does the actual query that’s sent to the server look like? Can you output the full aggregation created and show that?