thedodd / wither

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

Model.update should still be able to take a filter document. #20

Closed thedodd closed 5 years ago

thedodd commented 5 years ago

In order to be able to query on the target document more precisely, we need to update the Model.update method to also take an optional filter document. The document will be unpacked and the _id field will be forced to be the ObjectId of the current model. This will ensure consistent behavior.

This is needed when you need to conditionally perform an update on the target document and you want to use the DB as your mechanism of staving off race conditions. EG: you want to update a field on the model, but only if the field is currently null. If it is not null, then someone else beat you to the update and the operation should fail.