@@ -658,6 +658,56 @@ value of ``imdb.rating`` of those matches by using the
658658 :start-after: begin aggregation with filter
659659 :end-before: end aggregation with filter
660660
661+ Aggregate By Group Examples
662+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
663+
664+ You can perform an aggregation operation on a group
665+ of documents by using the following query builder
666+ methods, which return a single aggregated value for
667+ each group:
668+
669+ - ``countByGroup()``: Retrieves a count of the given field's
670+ distinct values for each group
671+
672+ - ``minByGroup()``: Retrieves the minimum value of the
673+ given field for each group
674+
675+ - ``maxByGroup()``: Retrieves the maximum value of the
676+ given field for each group
677+
678+ - ``sumByGroup()``: Retrieves the sum of a given field's
679+ values for each group
680+
681+ - ``avgByGroup()``: Retrieves the average of a given field's
682+ values for each group
683+
684+ countByGroup() Example
685+ ``````````````````````
686+
687+ The following example groups documents in the ``movies``
688+ collection by their ``imdb.rating`` values and returns
689+ the number of documents that have each distinct
690+ ``imdb.rating`` value:
691+
692+ .. literalinclude:: /includes/query-builder/QueryBuilderTest.php
693+ :language: php
694+ :dedent:
695+ :start-after: begin count by group
696+ :end-before: end count by group
697+
698+ sumByGroup() Example
699+ ````````````````````
700+
701+ The following example groups documents in the ``movies``
702+ collection by their ``year`` values and returns
703+ a sum of ``awards.wins`` values for each year:
704+
705+ .. literalinclude:: /includes/query-builder/QueryBuilderTest.php
706+ :language: php
707+ :dedent:
708+ :start-after: begin sum by group
709+ :end-before: end sum by group
710+
661711.. _laravel-options-query-builder:
662712
663713Set Query-Level Options
0 commit comments