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

204
Visualizações
How to remove a field from field that is being populated mongoose

so

async findAll(req, res) {
        await WorkModel.find({})
            .sort('when')
            .populate({path: 'artists', populate: { path: 'categories'}})
            .then(response => {
                return res.status(200).json(response);
            })
            .catch(error => {
                return res.status(500).json(error);
            });
    }

I need in this function remove works from the population that is happen is artists, but when I try like passing

{path: 'artists -works', populate: { path: 'categories'}}

I'm getting {} response, or even when I try

{path: 'artists -works', populate: { path: 'categories'}}, '-works'

in the populate

the method just get a stackTrace, I'm out of clues rn, please help me out.

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

If you want to select only works field from categories collection, using populate. you can do it using select !

Try this code it's help you ! For more help mongoosejs.com

async findAll(req, res) {
        await WorkModel.find({})
            .sort('when')
            .populate({path: 'artists', populate: { path: 'categories', select: 'works'}})
            .then(response => {
                return res.status(200).json(response);
            })
            .catch(error => {
                return res.status(500).json(error);
            });
    }
about 4 years ago · Juan Pablo Isaza Relatório

0

So the solution to remove the works from many-to-many relation in artists was

 async findAll(req, res) {
        await WorkModel.find({})
            .sort('when')
            .populate({path: 'artists', select:'-works', populate: { path: 'categories'}})
            .then(response => {
                return res.status(200).json(response);
            })
            .catch(error => {
                return res.status(500).json(error);
            });
    }

Thanks for all the comments, really helped out.

about 4 years ago · Juan Pablo Isaza Relatório
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