Automattic / Automattic/mongoose
Use findOneAndUpdate for save?
- Dominant language
- JavaScript
- Stars
- 27.5k
- Forks
- 4k
- Avg merge
- 2d 5h
- Merged PRs (30d)
- 32
Description
This is a bug in how the save function operates.
The save function assumes that all values are properly updated and returns the same object passed to save (with minor changes such as version update).
Any updated to the object that mongoose doesn't recognize will be affected. For example if you update a date with setMonth (without using markModified), mongoose.js will not recognize it and will claim the object was properly updated on save, when it fact it wasn't.
The desired outcome should be an error returned if the return value from the database does not match the saved object. If returning an error doesn't work, then the returned object should be the one from the database, not the one that was passed to the save function.
Currently using Node v8.0.0, Mongoose v4.10.5, and MongoDB v3.4.1.
Contributor guide
Research direction
Start with the save function and reproduce the described setMonth case using the reported Mongoose and MongoDB versions. Compare the object passed to save with the value persisted and returned by the database; done means save reports a mismatch or returns the database version instead of silently claiming the update succeeded.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, mongodb, node.js
- Domain
- backend, database
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100