- Notifications
You must be signed in to change notification settings - Fork590
Closed
Labels
Description
Raised inhttps://forum.m-siemens.de/d/29-how-to-use-matches-with-int-values
Basically, withany 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:
>>>db.search(User.groups.any(['admin','sudo']))[{'name':'user2','groups': ['admin','user']}, {'name':'user3','groups': ['sudo','user']}]>>>db.search(User.groups.all(['admin','user']))[{'name':'user2','groups': ['admin','user']}]
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:
>>>db.search(User.name.in(['admin','user']))[{'name':'admin'}][{'name':'user'}]
The issue is mainly naming. We can't name the methodin 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:
>>>db.search(User.name.test(lambdaname:namein ['admin','user']))[{'name':'admin'}][{'name':'user'}]