Can anyone help me out with using $search in $lookup?
It works fine if I use a static string instead of searchId, but I’m not able to use a variable from the “let” definition block. Anyone knows how to resolve variables inside the $search function?
Can anyone help me out with using $search in $lookup?
It works fine if I use a static string instead of searchId, but I’m not able to use a variable from the “let” definition block. Anyone knows how to resolve variables inside the $search function?
$lookup variables can only be referenced inside $expr
and I don’t believe that’s supported in $search
at the moment.
Oh no, that’s a pity.
Just to confirm - the question here is for the $search
aggregation stage. Is your answer also valid for $search
field of the $text
operator? For example, a $lookup
stage with the following content:
{
from: "OtherCollection",
let: {
otherName: "$name",
},
pipeline: [
{
$match: {
$text: {
$search: "$$otherName",
},
},
},
],
as: "references",
}
This is not expected to work as well, right?
Correct.
$$expr is a top level expression.