Automattic / Automattic/mongoose

Document.update() only returns first validation error, whereas Model.save() or Document.save() return all

Open
#3,037 3 comments 1 reaction 0 assignees View on GitHub
Dominant language
JavaScript
Stars
27.5k
Forks
4k
Avg merge
2d 7h
Merged PRs (30d)
35

Description

If you call Model.update(), specifying the object key you want to update, and the fields to be updated, but include data that fails the schema validation, the callback function receives a single error object detailing only the first error encountered.

When you use Model.save() or Document.save() in the same context, you get a error object that contains an 'errors' object with properties for each field that failed.

It seems that the save() functionality is more desirable, as it means all errors can be reported to the user at the same time.

Contributor guide

Open the contributing guide

Research direction

Reproduce the issue with Model.update() using a schema and multiple invalid fields, then compare its callback error with Model.save() and Document.save(). Inspect the update validation path and verify that the callback exposes validation errors for every failing field rather than only the first.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, mongodb, node.js
Domain
backend, databases
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.