Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

130
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda