-
Notifications
You must be signed in to change notification settings - Fork 40
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
How to Specify Enum Literals? #76
Comments
Hey there. So, take a look at the bson docs here: https://docs.rs/bson/1.2.0/bson/ser/fn.to_bson.html Though there are a few ways to deal with this, using this function to serialize your type as Bson is probably best, as it will ensure that if you actually have some BSON incompatible serde rules on your enum, this function will catch such issues (as an error). That is generally what I would recommend in such cases, as this is the same mechanism which would be used if you have that enum type embedded in a struct which you are serializing/deserializing as bson. |
So I would instead do something like "$set": doc! {
"standing": to_bson(&UserStanding::Active).unwrap()
} Is that correct? |
In another case, imagine I have struct User {
pub my_field: Option<MyWeirdType>
} How can I find all documents which have a Some variant without explicitly constructing the thing I'm looking for? { "my_field": {"tag": "Some" } } This feels ugly and error-prone, I hope there is a better way to do this. |
@wbrickner so, at the end of the day the enum is just another field in the DB. So as long as your enum field in indexed in the DB (otherwise it may be dead slow and may negatively impact your DB), then you have to treat it like any other field you are filtering on. So if you know that your enum value serializes as Thoughts? |
Hello 👋🏻
I am trying to update a document.
I need to set the field
standing
, of typeUserStanding
:When I try to do this:
I get the error
Thank you.
The text was updated successfully, but these errors were encountered: