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

207
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
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