@@ -399,7 +399,7 @@ of the ``year`` field for documents in the ``movies`` collections.
399
399
.. _laravel-query-builder-aggregations:
400
400
401
401
Aggregations
402
- ~~~~~~~~~~~~
402
+ ------------
403
403
404
404
The examples in this section show the query builder syntax you
405
405
can use to perform **aggregations**. Aggregations are operations
@@ -417,7 +417,7 @@ aggregations to compute and return the following information:
417
417
.. _laravel-query-builder-aggregation-groupby:
418
418
419
419
Results Grouped by Common Field Values Example
420
- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
420
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
421
421
422
422
The following example shows how to use the ``groupBy()`` query builder method
423
423
to retrieve document data grouped by shared values of the ``runtime`` field.
@@ -476,7 +476,7 @@ This example chains the following operations to match documents from the
476
476
.. _laravel-query-builder-aggregation-count:
477
477
478
478
Number of Results Example
479
- ^^^^^^^^^^^^^^^^^^^^^^^^^
479
+ ~~~~~~~~~~~~~~~~~~~~~~~~~
480
480
481
481
The following example shows how to use the ``count()``
482
482
query builder method to return the number of documents
@@ -491,7 +491,7 @@ contained in the ``movies`` collection:
491
491
.. _laravel-query-builder-aggregation-max:
492
492
493
493
Maximum Value of a Field Example
494
- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
494
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
495
495
496
496
The following example shows how to use the ``max()``
497
497
query builder method to return the highest numerical
@@ -507,7 +507,7 @@ value of the ``runtime`` field from the entire
507
507
.. _laravel-query-builder-aggregation-min:
508
508
509
509
Minimum Value of a Field Example
510
- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
510
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
511
511
512
512
The following example shows how to use the ``min()``
513
513
query builder method to return the lowest numerical
@@ -523,7 +523,7 @@ collection:
523
523
.. _laravel-query-builder-aggregation-avg:
524
524
525
525
Average Value of a Field Example
526
- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
526
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
527
527
528
528
The following example shows how to use the ``avg()``
529
529
query builder method to return the numerical average, or
@@ -539,7 +539,7 @@ the entire ``movies`` collection.
539
539
.. _laravel-query-builder-aggregation-sum:
540
540
541
541
Summed Value of a Field Example
542
- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
542
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
543
543
544
544
The following example shows how to use the ``sum()``
545
545
query builder method to return the numerical total of
@@ -556,7 +556,7 @@ collection:
556
556
.. _laravel-query-builder-aggregate-matched:
557
557
558
558
Aggregate Matched Results Example
559
- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
559
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
560
560
561
561
The following example shows how to aggregate data
562
562
from results that match a query. The query matches all
@@ -1035,16 +1035,20 @@ following MongoDB-specific write operations:
1035
1035
Upsert a Document Example
1036
1036
~~~~~~~~~~~~~~~~~~~~~~~~~
1037
1037
1038
- You can perform an upsert operation by taking either of the following
1039
- actions :
1038
+ Starting in v4.7, you can perform an upsert operation by using either of
1039
+ the following methods :
1040
1040
1041
1041
- Use the ``upsert()`` query builder method. When you use this method,
1042
- you can perform a batch upsert to change or insert multiple documents
1042
+ you can perform a ** batch upsert** to change or insert multiple documents
1043
1043
in one operation.
1044
- - Use the ``update()`` query builder method and specify the ``upsert`` option.
1044
+
1045
+ - Use the ``update()`` query builder method and specify the ``upsert``
1046
+ option to update all documents that match the query filter or insert
1047
+ one document if no documents are matched. Only this method is
1048
+ supported in versions v4.6 and earlier.
1045
1049
1046
1050
Upsert Method
1047
- `````````````
1051
+ ^^^^^^^^^^^^^
1048
1052
1049
1053
The ``upsert()`` query builder method accepts the following parameters:
1050
1054
@@ -1079,7 +1083,7 @@ The ``upsert()`` query builder method returns the sum of the number of documents
1079
1083
operation updated, inserted, and modified.
1080
1084
1081
1085
Update Method
1082
- `````````````
1086
+ ^^^^^^^^^^^^^
1083
1087
1084
1088
The following example shows how to use the ``update()`` query builder method
1085
1089
and ``upsert`` option to update the matching document or insert one with the
0 commit comments