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

123
Views
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
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!