-
Notifications
You must be signed in to change notification settings - Fork 553
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Maybe add a way to check if one item of a list of values exists #164
Comments
How about |
My suggestion would be |
@mlapierre @eugene-eeo Great suggestions! So a method could look like this: db.search(User.name.one_of(['admin', 'user']))
# or
db.search(User.name.in_(['admin', 'user'])) To my eyes, the first option looks slightly better, but that's just my opinion. What do other folks think? |
I'd vote for the latter since "in" seems to be more intuitive - is the User.name "in" a list of names ??? |
My issue with |
Faiir point re |
So we have three suggestions now: # Variant 1:
db.search(User.name.one_of(['admin', 'user']))
# Variant 2:
db.search(User.name.in_(['admin', 'user']))
# Variant 3:
db.search(User.name.is_in(['admin', 'user'])) Personally I would lean towards It seems to me like |
@msiemens On reflection (despite what I mentioned earlier in the thread) I think you are correct - |
Raised in https://forum.m-siemens.de/d/29-how-to-use-matches-with-int-values
Basically, with
any
andall
we check, if a document's field – which is a list of values – contains a given value or only is a given value. From the docs:Note how in this case the field we check is a list. Now, right now we don't have a way for the reverse operation: if the field is a value, check if it's contained in a list. It could be something like this:
The issue is mainly naming. We can't name the method
in
as it's a Python keyword. I'm torn between calling itpart_of
orcontained_in
but both aren't exactly really intuitive when I think about it.By the way, the workaround for now is using a custom test function:
The text was updated successfully, but these errors were encountered: