Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

187
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!