thedodd / wither

An ODM for MongoDB built on the official MongoDB Rust driver.
https://docs.rs/wither
Other
324 stars 40 forks source link

Partial updates and typed documents #91

Open alexkirsz opened 2 years ago

alexkirsz commented 2 years ago

Hey! Thanks for building this crate :)

Are there any plans for enabling partial updates with Model::save? As I understand it, right now, calling save will send the whole document to the database instead of only the fields that were changed.

While this can already be done today using Model::update, this involves giving up type-safety, as update accepts a Document which knows nothing of the underlying model. My main concern is with typos and refactoring: if I rename or delete a field in the underlying schema:

  1. the compiler won't complain if there are doc! calls that still refer to this field.
  2. rust-analyzer won't be able to refactor it automatically.

(2) is less of a concern, but (1) seems problematic.

Cheers, Alex