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
});
};
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.