So, I have indexed a field in "terms" collection, and I am performing a lookup in that collection. Everything is working perfectly except that I am not able to use the defined variable for searching purposes.
{
"$lookup": {
"from": "terms",
"as": "matched_terms",
"let": {"localKeywordText": "$keywordText"},
"pipeline": [
{"$match": {"$text": {"$search": "after birth bath soak"}}},
{"$project": {"text": 1, "match_criteria": 1, "account_id": 1, "_id": 0}},
{"$sort": {"score": {"$meta": "textScore"}}},
{"$match": {"account_id": object_id}},
{"$limit": 5}
]
}
},
The above query is running as expected, but I want to use the $$localKeywordText variable to perform the search operation. Putting the $text operator inside an $expr lead to the error:
Unrecognized expression '$text', full error: {'ok': 0.0, 'errmsg': "Unrecognized expression '$text'", 'code': 168, 'codeName': 'InvalidPipelineOperator'}