Advertising mongoose Chinese document translation recruitmenthttps://github.com/ssshooter/…
. save() and update()
- Update is more efficient than save () after find, because it doesn’t need to read the whole document.
- Mongoose update is mongodb update, but mongoose save may be mongodb insert or update.
- As for save, mongoose will automatically diff the new document and only change the updated part. This is conducive to atomicity.
- Update cannot trigger middleware. Validation cannot be triggered by default, but can be modified.
Update() and findoneandupdate()
- Update() returns the number of data processing entries
- Findoneandupdate() returns the processed data
- In short, if you need to obtain data, use findoneandupdate(). If you only need to modify the data without paying attention to the modified data, use update().
Reference articles
https://stackoverflow.com/que…
https://stackoverflow.com/que…