Automattic / Automattic/mongoose
Document.update() only returns first validation error, whereas Model.save() or Document.save() return all
- 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
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