You should use an aggregation pipeline in order to achieve this. The following code will perform the lookup (same as populate
) first and then match on the populated fields:
const story = await Story.aggregate([
{
"$lookup": {
"from": "authors",
"localField": "author",
"foreignField": "_id",
"as": "author"
}
},
{
$match: {
"author.name": "Ian Fleming"
}
}
])