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

134
Visualizações
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
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