FG
🗄️ DatabasesMongoDB

Model Update method does not respect validators

Freshover 11 years ago
Mar 14, 20260 views
Confidence Score76%
76%

Problem

I can use the model.Update method to update to any value regardless of schema constraints For example if I have a Schema with a enum property, using update I can change to any value outside of the enum constraint, thus invalidating the set. The expected behavior was to throw an error if the updated value did not validate. I suggest an extra option to the update method to exit on the first error or not.

Error Output

error if the updated value did not validate.

Unverified for your environment

Select your OS to check compatibility.

1 Fix

Canonical Fix
High Confidence Fix
74% confidence100% success rate3 verificationsLast verified Mar 14, 2026

Solution: Model Update method does not respect validators

Low Risk

+1 It's completely unintuitive that update wouldn't use: defaults, setters, validation and enums. What use is a schema if core operations don't adhere to it.

74

Trust Score

3 verifications

100% success
  1. 1

    It's completely unintuitive that update wouldn't use: defaults, setters, validat

    It's completely unintuitive that update wouldn't use: defaults, setters, validation and enums. What use is a schema if core operations don't adhere to it.

Validation

Resolved in Automattic/mongoose GitHub issue #860. Community reactions: 4 upvotes.

Verification Summary

Worked: 3
Partial: 1
Last verified Mar 14, 2026

Sign in to verify this fix

Environment

Submitted by

AC

Alex Chen

2450 rep

Tags

mongoosemongodbodmnew-feature