@@ 546-573 (lines=28) @@ | ||
543 | * @param array $options |
|
544 | * @return mixed |
|
545 | */ |
|
546 | public function max($field, array $query = [], array $options = ['maxTimeMS' => 0]) |
|
547 | { |
|
548 | $this->validateQueryOptions($options); |
|
549 | ||
550 | $this->logger->info( |
|
551 | sprintf('Maximum value in field %s', $field), |
|
552 | [ |
|
553 | 'filter' => $query, |
|
554 | 'options' => $options |
|
555 | ] |
|
556 | ); |
|
557 | ||
558 | $result = $this->findBy( |
|
559 | $query, |
|
560 | [ |
|
561 | Query::PROJECTION => [ |
|
562 | $field => true |
|
563 | ], |
|
564 | Query::SORT => [ |
|
565 | $field => -1 |
|
566 | ], |
|
567 | Query::LIMIT => 1 |
|
568 | ] |
|
569 | )->toArray(); |
|
570 | ||
571 | return ArrayAccessor::dget($result, '0.' . $field); |
|
572 | ||
573 | } |
|
574 | ||
575 | /** |
|
576 | * Return the min value for a field in a collection |
|
@@ 583-609 (lines=27) @@ | ||
580 | * @param array $options |
|
581 | * @return \Traversable |
|
582 | */ |
|
583 | public function min($field, array $query = [], array $options = ['maxTimeMS' => 0]) |
|
584 | { |
|
585 | $this->validateQueryOptions($options); |
|
586 | ||
587 | $this->logger->info( |
|
588 | sprintf('Minimum value in field %s', $field), |
|
589 | [ |
|
590 | 'filter' => $query, |
|
591 | 'options' => $options |
|
592 | ] |
|
593 | ); |
|
594 | ||
595 | $result = $this->findBy( |
|
596 | $query, |
|
597 | [ |
|
598 | Query::PROJECTION => [ |
|
599 | $field => true |
|
600 | ], |
|
601 | Query::SORT => [ |
|
602 | $field => 1 |
|
603 | ], |
|
604 | Query::LIMIT => 1 |
|
605 | ] |
|
606 | )->toArray(); |
|
607 | ||
608 | return ArrayAccessor::dget($result, '0.' . $field); |
|
609 | } |
|
610 | ||
611 | /** |
|
612 | * @param $field |