thedodd / wither

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

Make the `id` field's name and type changable. #39

Closed magiclen closed 4 years ago

magiclen commented 5 years ago

Sometimes we don't want that the id field is named id, and don't want it to be an ObjectId (Option<mongodb::oid::ObjectId> precisely).

Perhaps wither can allow the following code in the future:

#[derive(Serialize, Deserialize, Model)]
struct Document {
    #[model(id)]
    #[serde(rename = "_id")]
    uid: u64
}
thedodd commented 5 years ago

@magiclen I've given this a decent bit of thought since before setting out to build this crate. I have some discussion points here: https://docs.rs/wither/0.8.0/wither/model/trait.Model.html#derive starting with the line For now, it seems logical to disallow customization of the PK.

What are your thoughts on that? Is there a case which can not be satisfied by simply adding a unique index to another field and using that as the PK? Is it mostly a matter of semantics and keeping things terse? Is it a problem with BSON OIDs?

thedodd commented 5 years ago

@magiclen just wanted to see if you have any thoughts on the response above.