i am trying to filter out a nested record based on my searchKey .for Example: patient - >provider want to search a patient and an provider together based on searchKey.
But when i'm triggering searchkey with patient details it's working but when i put any keyword related to provider (want to search provider) but this time filter not working. here is my code:
patients = await Patient.find({
$or: [
{ firstName: { $regex: searchKey, $options: "i" } },
{ lastName: { $regex: searchKey, $options: "i" } },
{ socialSecurityNumber: { $regex: searchKey, $options: "i" } },
],
provider: currentUser,
}).populate({ path: "provider", select: "firstName lastName", match : {
$or: [
{lastName: { $regex: searchKey,$options: "i" }},
{firstName: { $regex: searchKey,$options: "i" }},
]
} })
.populate({ path: "gender", select: "name -_id" })
.skip(pageSize * pageNumber - pageSize)
.limit(pageSize).lean();