thedodd / wither

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

[Docs] How does projection work in Rust? #80

Open wbrickner opened 3 years ago

wbrickner commented 3 years ago

Hello,

wondering how this library can support document projection if not every field is an Option<T>?

For instance if I only want one field from matching documents, how is this possible in Wither, which returns my struct back to me?

It is supported under options, but I think deserialization will fail in this case, otherwise the application will have entered an unsound state.

Thank you.

thedodd commented 3 years ago

Hey Will, projection in Wither runs a bit counter to the purpose of Wither, which is to provide model-based interaction with your MongoDB data. You absolutely can use projections with the underlying driver, but you will get a raw BSON document back instead of a model instance.