@@ -1068,6 +1068,23 @@ the ``imdb.votes`` field in the matched document:
1068
1068
The ``increment()`` query builder method returns the number of documents that the
1069
1069
operation updated.
1070
1070
1071
+ You can also use the ``incrementEach()`` query builder method to increment multiple
1072
+ values in a single operation. The following example uses the ``incrementEach()``
1073
+ method to increase the values of the ``awards.wins`` and ``imdb.votes`` fields in the
1074
+ matched document:
1075
+
1076
+ .. literalinclude:: /includes/query-builder/QueryBuilderTest.php
1077
+ :language: php
1078
+ :dedent:
1079
+ :start-after: begin increment each
1080
+ :end-before: end increment each
1081
+
1082
+ .. note::
1083
+
1084
+ If you pass a field to the ``increment()`` or ``incrementEach()`` method that
1085
+ has no value or doesn't exist in the matched documents, these methods initialize
1086
+ the specified field with the increment value.
1087
+
1071
1088
.. _laravel-mongodb-query-builder-decrement:
1072
1089
1073
1090
Decrement a Numerical Value Example
@@ -1086,6 +1103,23 @@ matched document:
1086
1103
The ``decrement()`` query builder method returns the number of documents that the
1087
1104
operation updated.
1088
1105
1106
+ You can also use the ``decrementEach()`` query builder method to decrement multiple
1107
+ values in a single operation. The following example uses the ``decrementEach()``
1108
+ method to decrease the values of the ``metacritic`` and ``imdb.rating`` fields in the
1109
+ matched document:
1110
+
1111
+ .. literalinclude:: /includes/query-builder/QueryBuilderTest.php
1112
+ :language: php
1113
+ :dedent:
1114
+ :start-after: begin decrement each
1115
+ :end-before: end decrement each
1116
+
1117
+ .. note::
1118
+
1119
+ If you pass a field to the ``decrement()`` or ``decrementEach()`` method that
1120
+ has no value or doesn't exist in the matched documents, these methods initialize
1121
+ the specified field with the decrement value.
1122
+
1089
1123
.. _laravel-mongodb-query-builder-push:
1090
1124
1091
1125
Add an Array Element Example
0 commit comments