From 859d62e65428bc9972f878286794fb2f14483dd0 Mon Sep 17 00:00:00 2001 From: norareidy Date: Wed, 31 Jul 2024 14:58:37 -0400 Subject: [PATCH 1/3] DOCSP-41741: incrementEach and decrementEach --- .../query-builder/QueryBuilderTest.php | 28 +++++++++++++++ docs/query-builder.txt | 34 +++++++++++++++++++ 2 files changed, 62 insertions(+) diff --git a/docs/includes/query-builder/QueryBuilderTest.php b/docs/includes/query-builder/QueryBuilderTest.php index a6a8c752d..84036eb39 100644 --- a/docs/includes/query-builder/QueryBuilderTest.php +++ b/docs/includes/query-builder/QueryBuilderTest.php @@ -532,6 +532,20 @@ public function testIncrement(): void $this->assertIsInt($result); } + public function testIncrementEach(): void + { + // begin increment each + $result = DB::table('movies') + ->where('title', 'Lost in Translation') + ->incrementEach([ + 'awards.wins' => 2, + 'imdb.votes' => 1050, + ]); + // end increment each + + $this->assertIsInt($result); + } + public function testDecrement(): void { // begin decrement @@ -543,6 +557,20 @@ public function testDecrement(): void $this->assertIsInt($result); } + public function testDecrementEach(): void + { + // begin decrement each + $result = DB::table('movies') + ->where('title', 'Dunkirk') + ->decrementEach([ + 'metacritic' => 1, + 'imdb.rating' => 0.4, + ]); + // end decrement each + + $this->assertIsInt($result); + } + public function testPush(): void { // begin push diff --git a/docs/query-builder.txt b/docs/query-builder.txt index 041893e34..859b9c003 100644 --- a/docs/query-builder.txt +++ b/docs/query-builder.txt @@ -1068,6 +1068,23 @@ the ``imdb.votes`` field in the matched document: The ``increment()`` query builder method returns the number of documents that the operation updated. +You can also use the ``incrementEach()`` query builder method to increment multiple +values in a single operation. The following example uses the ``incrementEach()`` +method to increase the values of the ``awards.wins`` and ``imdb.votes`` fields in the +matched document: + +.. literalinclude:: /includes/query-builder/QueryBuilderTest.php + :language: php + :dedent: + :start-after: begin increment each + :end-before: end increment each + +.. note:: + + If you pass a field to the ``increment()`` or ``incrementEach()`` method that + has no value or doesn't exist in the matched documents, these methods initialize + the specified field with the increment value. + .. _laravel-mongodb-query-builder-decrement: Decrement a Numerical Value Example @@ -1086,6 +1103,23 @@ matched document: The ``decrement()`` query builder method returns the number of documents that the operation updated. +You can also use the ``decrementEach()`` query builder method to decrement multiple +values in a single operation. The following example uses the ``decrementEach()`` +method to decrease the values of the ``metacritic`` and ``imdb.rating`` fields in the +matched document: + +.. literalinclude:: /includes/query-builder/QueryBuilderTest.php + :language: php + :dedent: + :start-after: begin decrement each + :end-before: end decrement each + +.. note:: + + If you pass a field to the ``decrement()`` or ``decrementEach()`` method that + has no value or doesn't exist in the matched documents, these methods initialize + the specified field with the decrement value. + .. _laravel-mongodb-query-builder-push: Add an Array Element Example From a1fd9d205a6bec96d0708bbea238ea82937e92e5 Mon Sep 17 00:00:00 2001 From: norareidy Date: Wed, 31 Jul 2024 15:01:48 -0400 Subject: [PATCH 2/3] clarify v4.8 --- docs/query-builder.txt | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/docs/query-builder.txt b/docs/query-builder.txt index 859b9c003..2060a09a2 100644 --- a/docs/query-builder.txt +++ b/docs/query-builder.txt @@ -1068,10 +1068,10 @@ the ``imdb.votes`` field in the matched document: The ``increment()`` query builder method returns the number of documents that the operation updated. -You can also use the ``incrementEach()`` query builder method to increment multiple -values in a single operation. The following example uses the ``incrementEach()`` -method to increase the values of the ``awards.wins`` and ``imdb.votes`` fields in the -matched document: +Starting in {+odm-short+} v4.8, you can also use the ``incrementEach()`` query +builder method to increment multiple values in a single operation. The following +example uses the ``incrementEach()`` method to increase the values of the ``awards.wins`` +and ``imdb.votes`` fields in the matched document: .. literalinclude:: /includes/query-builder/QueryBuilderTest.php :language: php @@ -1103,10 +1103,10 @@ matched document: The ``decrement()`` query builder method returns the number of documents that the operation updated. -You can also use the ``decrementEach()`` query builder method to decrement multiple -values in a single operation. The following example uses the ``decrementEach()`` -method to decrease the values of the ``metacritic`` and ``imdb.rating`` fields in the -matched document: +Starting in {+odm-short+} v4.8, you can also use the ``decrementEach()`` query builder +method to decrement multiple values in a single operation. The following example uses +the ``decrementEach()`` method to decrease the values of the ``metacritic`` and ``imdb.rating`` +fields in the matched document: .. literalinclude:: /includes/query-builder/QueryBuilderTest.php :language: php From 74e58d174fb1e8c775398a11d512a2f566bed2ca Mon Sep 17 00:00:00 2001 From: norareidy Date: Wed, 31 Jul 2024 15:09:30 -0400 Subject: [PATCH 3/3] edits --- docs/query-builder.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/query-builder.txt b/docs/query-builder.txt index 2060a09a2..ccd381228 100644 --- a/docs/query-builder.txt +++ b/docs/query-builder.txt @@ -1083,7 +1083,7 @@ and ``imdb.votes`` fields in the matched document: If you pass a field to the ``increment()`` or ``incrementEach()`` method that has no value or doesn't exist in the matched documents, these methods initialize - the specified field with the increment value. + the specified field to the increment value. .. _laravel-mongodb-query-builder-decrement: @@ -1118,7 +1118,7 @@ fields in the matched document: If you pass a field to the ``decrement()`` or ``decrementEach()`` method that has no value or doesn't exist in the matched documents, these methods initialize - the specified field with the decrement value. + the specified field to the decrement value. .. _laravel-mongodb-query-builder-push: