79817435

Date: 2025-11-12 07:19:46
Score: 0.5
Natty:
Report link

When you set a field option like { select: false } in a Mongoose schema, it only affects queries such as .find(), .findOne(), .findById(), .findOneAndUpdate(), etc.

It does not affect .create() or .save(), because those operations don’t query the database — they just create and return the new document object.

So, if you want to exclude a field like password when returning a newly created user, you’ll need to explicitly call .select('-password') on the query after creating or fetching it.

According to the Mongoose docs for SchemaTypeOptions.select

Whether to include or exclude this path by default when loading documents using find(), findOne(), etc.

Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Starts with a question (0.5): When you
  • Low reputation (1):
Posted by: omarElsayed Muhammad