Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

125
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda