Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

131
Views
not able to filter an nested record in find method and in populate method together

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();
over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!