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

133
Views
Query by populated model attribute

I have the following data example queried from mongoose:

  {
    _id: new ObjectId("622a0cbef19bd38844b8755d"),
    creator: new ObjectId("61e955a77aece40e1e5b5535"),
    description: 'XYZ',
    category: { _id: new ObjectId("6226704b9410d37a7686224b"), public: true },
    active: true,
  }

I would like to get all documents where category.public equals true

In my controller I tried the following query:

    const task = await Task.find({
      creator: userid,
      active: true,
    }).populate({ path: 'category', model: Category, select: 'public' })
      .where('category.public').equals(true)
      .sort({
        active: 'desc',
      });

But the result is always empty. I know that there are some matching documents and if I delete .where('category.public').equals(true) it returns all records. Any ideas how to query with a populated attribute? There's probably something wrong with my approach.

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!