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

131
Visualizações
filter nested in populate

Good morning everyone I have a problem with the populate issue in mongoose especially with the filters issue, I will explain what I want to do:

this is my current code:

      let consult = await Experiences.find({}).populate("comments", {
    experienceId: 0,
    __v: 0
  }).populate({
    path: "city",
    __v: 0,
    match: { 'name': {$in: req.query.city}},
    select: ['name','state']
  });

what I need here is to filter by city the total results not only of the city field in the populate, since it returns me the 2 data that I have and the city of which does not meet the condition in null I need is not to show it directly.

it returns:

{
"success": true,
"consult": [
    {
        "comments": [],
        "_id": "616a96b05550a5f9959e724a",
        "name": "Museo",
        "city": null,
        "date": "2021-10-16T09:09:04.495Z",
        "__v": 1,
        "rate": 5
    },
    {
        "comments": [],
        "_id": "616a9dbeebc9e9ff2c95431a",
        "name": "Museo  nuevo",
        "city": {
            "_id": "616a9da2ebc9e9ff2c954317",
            "name": "Miami"
        },
        "date": "2021-10-16T09:39:10.420Z",
        "__v": 0
    }
]
}

i need this:

{
"success": true,
"consult": [
    {
        "comments": [],
        "_id": "616a9dbeebc9e9ff2c95431a",
        "name": "Museo  nuevo",
        "city": {
            "_id": "616a9da2ebc9e9ff2c954317",
            "name": "Miami"
        },
        "date": "2021-10-16T09:39:10.420Z",
        "__v": 0
    }
]
}
about 4 years ago · Juan Pablo Isaza
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