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

181
Vistas
Mongoose Select Method Not Working As Expected

Trying to simply include a field that has select set to false within the schema. Overriding it with select method is not working for some reason. Exclusion of other fields work but inclusion doesn't. In the following example I'm trying to include the "active_account" field. What could be causing this behavior?

Schema

const Schema = new mongoose.Schema({
    active_account: {
        type: Boolean,
        default: true,
        select: false
    }
})

Function

exports.deactivate_user = async ( req , res , next ) => {
    
    const user = await User.findByIdAndUpdate( req.params.id , { active_account: false } ).select( '+active_account' );
    
    res.status( 200 ).json({
        status: 'Success',
        data: user
    });
};
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

According to docs;

A.findByIdAndUpdate(id, update, options) // returns Query

So,

 const user = await User.findByIdAndUpdate( 
                                           req.params.id, //id
                                           { active_account: false }, //update
                                           { select: 'active_account', new: true } //options
                                          );

set new = true to get the updated version of data.

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