Check if a condition is met by any document in a list, where a condition can also be a sequence (e.g. list). >>> Query().f1.any(Query().f2 == 1) Matches:: {'f1': [{'f2': 1}, {'f2': 0}]} >>> Query().f1.any([1, 2, 3]) Matches::
(self, cond: Union[QueryInstance, List[Any]])
| 391 | ) |
| 392 | |
| 393 | def any(self, cond: Union[QueryInstance, List[Any]]) -> QueryInstance: |
| 394 | """ |
| 395 | Check if a condition is met by any document in a list, |
| 396 | where a condition can also be a sequence (e.g. list). |
| 397 | |
| 398 | >>> Query().f1.any(Query().f2 == 1) |
| 399 | |
| 400 | Matches:: |
| 401 | |
| 402 | {'f1': [{'f2': 1}, {'f2': 0}]} |
| 403 | |
| 404 | >>> Query().f1.any([1, 2, 3]) |
| 405 | |
| 406 | Matches:: |
| 407 | |
| 408 | {'f1': [1, 2]} |
| 409 | {'f1': [3, 4, 5]} |
| 410 | |
| 411 | :param cond: Either a query that at least one document has to match or |
| 412 | a list of which at least one document has to be contained |
| 413 | in the tested document. |
| 414 | """ |
| 415 | if callable(cond): |
| 416 | def test(value): |
| 417 | return is_sequence(value) and any(cond(e) for e in value) |
| 418 | |
| 419 | else: |
| 420 | def test(value): |
| 421 | return is_sequence(value) and any(e in cond for e in value) |
| 422 | |
| 423 | return self._generate_test( |
| 424 | lambda value: test(value), |
| 425 | ('any', self._path, freeze(cond)) |
| 426 | ) |
| 427 | |
| 428 | def all(self, cond: Union['QueryInstance', List[Any]]) -> QueryInstance: |
| 429 | """ |