From 87ffd838911be50ad8707b92c9ab1416980416ae Mon Sep 17 00:00:00 2001 From: rustagir Date: Thu, 30 Jan 2025 09:29:00 -0500 Subject: [PATCH 01/21] DOCSP-38327: add qb examples to usage exs --- docs/includes/usage-examples/CountTest.php | 12 +- .../usage-examples/DeleteManyTest.php | 12 +- .../usage-examples/operation-description.rst | 5 +- docs/usage-examples.txt | 4 + docs/usage-examples/count.txt | 96 ++++++++++---- docs/usage-examples/deleteMany.txt | 118 ++++++++++++------ docs/usage-examples/find.txt | 2 +- docs/usage-examples/findOne.txt | 2 +- 8 files changed, 179 insertions(+), 72 deletions(-) diff --git a/docs/includes/usage-examples/CountTest.php b/docs/includes/usage-examples/CountTest.php index ecf53db47..948e8a993 100644 --- a/docs/includes/usage-examples/CountTest.php +++ b/docs/includes/usage-examples/CountTest.php @@ -29,12 +29,20 @@ public function testCount(): void ], ]); - // begin-count + // begin-eloquent-count $count = Movie::where('genres', 'Biography') ->count(); echo 'Number of documents: ' . $count; - // end-count + // end-eloquent-count + + // begin-qb-count + $count = DB::table('movies') + ->where('genres', 'Biography') + ->count(); + + echo 'Number of documents: ' . $count; + // end-qb-count $this->assertEquals(2, $count); $this->expectOutputString('Number of documents: 2'); diff --git a/docs/includes/usage-examples/DeleteManyTest.php b/docs/includes/usage-examples/DeleteManyTest.php index 5050f952e..6e53601b9 100644 --- a/docs/includes/usage-examples/DeleteManyTest.php +++ b/docs/includes/usage-examples/DeleteManyTest.php @@ -29,12 +29,20 @@ public function testDeleteMany(): void ], ]); - // begin-delete-many + // begin-eloquent-delete-many $deleted = Movie::where('year', '<=', 1910) ->delete(); echo 'Deleted documents: ' . $deleted; - // end-delete-many + // end-eloquent-delete-many + + // begin-qb-delete-many + $deleted = DB::table('movies') + ->where('year', '<=', 1910) + ->delete(); + + echo 'Deleted documents: ' . $deleted; + // end-qb-delete-many $this->assertEquals(2, $deleted); $this->expectOutputString('Deleted documents: 2'); diff --git a/docs/includes/usage-examples/operation-description.rst b/docs/includes/usage-examples/operation-description.rst index 68119a249..c68754475 100644 --- a/docs/includes/usage-examples/operation-description.rst +++ b/docs/includes/usage-examples/operation-description.rst @@ -1,2 +1,3 @@ -|operator-description| by creating a query builder, using a method such -as ``Model::where()`` or the ``DB`` facade to match documents in a collection, and then calling |result-operation|. +|operator-description| by using a method such as ``Model::where()`` or +methods from the ``DB`` facade to match documents, and then calling +|result-operation|. diff --git a/docs/usage-examples.txt b/docs/usage-examples.txt index 87a87df88..14478c004 100644 --- a/docs/usage-examples.txt +++ b/docs/usage-examples.txt @@ -43,6 +43,10 @@ operations. Each usage example includes the following components: - Example code that you can run from an application controller - Output displayed by the print statement +To learn more about the operations demonstrated in the usage examples, +see the :ref:`laravel-fundamentals-read-ops` and +:ref:`laravel-fundamentals-write-ops` guides. + How to Use the Usage Examples ----------------------------- diff --git a/docs/usage-examples/count.txt b/docs/usage-examples/count.txt index c3af477ee..aadd1e0c6 100644 --- a/docs/usage-examples/count.txt +++ b/docs/usage-examples/count.txt @@ -25,35 +25,79 @@ Count Documents .. replacement:: result-operation - the ``count()`` method to retrieve the results. + the ``count()`` method to retrieve the results Example ------- -This usage example performs the following actions: - -- Uses the ``Movie`` Eloquent model to represent the ``movies`` collection in the - ``sample_mflix`` database -- Counts the documents from the ``movies`` collection that match a query filter -- Prints the matching document count - -The example calls the following methods on the ``Movie`` model: - -- ``where()``: Matches documents in which the value of the ``genres`` field includes ``"Biography"``. -- ``count()``: Counts the number of matching documents. This method returns an integer value. - -.. io-code-block:: - - .. input:: ../includes/usage-examples/CountTest.php - :start-after: begin-count - :end-before: end-count - :language: php - :dedent: - - .. output:: - :language: console - :visible: false - - Number of documents: 1267 +Select from the following :guilabel:`Eloquent` and :guilabel:`Query +Builder` tabs to view usage examples for the same operation that use +each corresponding query syntax: + +.. tabs:: + + .. tab:: Eloquent + :tabid: eloquent-model-count + + This example performs the following actions: + + - Uses the ``Movie`` Eloquent model to represent the ``movies`` + collection in the ``sample_mflix`` database + - Counts the documents from the ``movies`` collection that match a + query filter + - Prints the matching document count + + The example calls the following methods on the ``Movie`` model: + + - ``where()``: Matches documents in which the value of the + ``genres`` field includes ``"Biography"`` + - ``count()``: Counts the number of matching documents and returns + the count as an integer + + .. io-code-block:: + + .. input:: ../includes/usage-examples/CountTest.php + :start-after: begin-eloquent-count + :end-before: end-eloquent-count + :language: php + :dedent: + + .. output:: + :language: console + :visible: false + + Number of documents: 1267 + + .. tab:: Query Builder + :tabid: query-builder-count + + This example performs the following actions: + + - Accesses the ``movies`` collection by calling the ``table()`` + method from the ``DB`` facade + - Counts the documents from the ``movies`` collection that match a + query filter + - Prints the matching document count + + The example calls the following query builder methods: + + - ``where()``: Matches documents in which the value of the + ``genres`` field includes ``"Biography"`` + - ``count()``: Counts the number of matching documents and returns + the count as an integer + + .. io-code-block:: + + .. input:: ../includes/usage-examples/CountTest.php + :start-after: begin-qb-count + :end-before: end-qb-count + :language: php + :dedent: + + .. output:: + :language: console + :visible: false + + Number of documents: 1267 .. include:: /includes/usage-examples/fact-edit-laravel-app.rst diff --git a/docs/usage-examples/deleteMany.txt b/docs/usage-examples/deleteMany.txt index cf8680184..965c14996 100644 --- a/docs/usage-examples/deleteMany.txt +++ b/docs/usage-examples/deleteMany.txt @@ -17,48 +17,90 @@ Delete Multiple Documents :depth: 1 :class: singlecol -You can delete multiple documents in a collection by calling the ``delete()`` method on an -object collection or a query builder. +You can delete multiple documents in a collection by calling the +``delete()`` method on an object collection or a query builder. -To delete multiple documents, pass a query filter to the ``where()`` method. Then, delete the -matching documents by calling the ``delete()`` method. - -Example -------- - -This usage example performs the following actions: - -- Uses the ``Movie`` Eloquent model to represent the ``movies`` collection in the - ``sample_mflix`` database -- Deletes documents from the ``movies`` collection that match a query filter -- Prints the number of deleted documents - -The example calls the following methods on the ``Movie`` model: - -- ``where()``: matches documents in which the value of the ``year`` field is less than or - equal to ``1910``. -- ``delete()``: deletes the matched documents. This method returns the number - of documents that the method successfully deletes. - -.. io-code-block:: - :copyable: true - - .. input:: ../includes/usage-examples/DeleteManyTest.php - :start-after: begin-delete-many - :end-before: end-delete-many - :language: php - :dedent: - - .. output:: - :language: console - :visible: false - - Deleted documents: 7 - -.. include:: /includes/usage-examples/fact-edit-laravel-app.rst +To delete multiple documents, pass a query filter to the ``where()`` +method. Then, delete the matching documents by calling the ``delete()`` +method. .. tip:: To learn more about deleting documents with the {+odm-short+}, see the :ref:`laravel-fundamentals-delete-documents` section of the Write Operations guide. +Example +------- + +Select from the following :guilabel:`Eloquent` and :guilabel:`Query +Builder` tabs to view usage examples for the same operation that use +each corresponding query syntax: + +.. tabs:: + + .. tab:: Eloquent + :tabid: eloquent-model-count + + This example performs the following actions: + + - Uses the ``Movie`` Eloquent model to represent the ``movies`` + collection in the ``sample_mflix`` database + - Deletes documents from the ``movies`` collection that match a + query filter + - Prints the number of deleted documents + + The example calls the following methods on the ``Movie`` model: + + - ``where()``: Matches documents in which the value of the + ``year`` field is less than or equal to ``1910`` + - ``delete()``: Deletes the matched documents and returns the + number of documents successfully deleted + + .. io-code-block:: + :copyable: true + + .. input:: ../includes/usage-examples/DeleteManyTest.php + :start-after: begin-eloquent-delete-many + :end-before: end-eloquent-delete-many + :language: php + :dedent: + + .. output:: + :language: console + :visible: false + + Deleted documents: 7 + + .. tab:: Query Builder + :tabid: query-builder-count + + This example performs the following actions: + + - Accesses the ``movies`` collection by calling the ``table()`` + method from the ``DB`` facade + - Deletes documents from the ``movies`` collection that match a + query filter + - Prints the number of deleted documents + + The example calls the following query builder methods: + + - ``where()``: Matches documents in which the value of the + ``year`` field is less than or equal to ``1910`` + - ``delete()``: Deletes the matched documents and returns the + number of documents successfully deleted + + .. io-code-block:: + + .. input:: ../includes/usage-examples/DeleteManyTest.php + :start-after: begin-qb-delete-many + :end-before: end-qb-delete-many + :language: php + :dedent: + + .. output:: + :language: console + :visible: false + + Deleted documents: 7 + +.. include:: /includes/usage-examples/fact-edit-laravel-app.rst diff --git a/docs/usage-examples/find.txt b/docs/usage-examples/find.txt index 957ece537..c70805541 100644 --- a/docs/usage-examples/find.txt +++ b/docs/usage-examples/find.txt @@ -25,7 +25,7 @@ Find Multiple Documents .. replacement:: result-operation - the ``get()`` method to retrieve the results. + the ``get()`` method to retrieve the results Pass a query filter to the ``where()`` method to retrieve documents that meet a set of criteria. When you call the ``get()`` method, MongoDB returns the diff --git a/docs/usage-examples/findOne.txt b/docs/usage-examples/findOne.txt index aa0e035f1..2b3109152 100644 --- a/docs/usage-examples/findOne.txt +++ b/docs/usage-examples/findOne.txt @@ -19,7 +19,7 @@ Find a Document .. replacement:: result-operation - the ``first()`` method to return one document. + the ``first()`` method to return one document If multiple documents match the query filter, ``first()`` returns the first matching document according to the documents' :term:`natural order` in the database or according to the sort order that you can specify From e2fb9fc3dd2f3f33568d511af7865ef969b1f76a Mon Sep 17 00:00:00 2001 From: rustagir Date: Thu, 30 Jan 2025 10:07:40 -0500 Subject: [PATCH 02/21] add imports --- docs/includes/usage-examples/CountTest.php | 2 ++ .../usage-examples/DeleteManyTest.php | 2 ++ docs/usage-examples/deleteMany.txt | 5 ++-- docs/usage-examples/deleteOne.txt | 25 ++++++++++--------- 4 files changed, 20 insertions(+), 14 deletions(-) diff --git a/docs/includes/usage-examples/CountTest.php b/docs/includes/usage-examples/CountTest.php index 948e8a993..f7a88d6fd 100644 --- a/docs/includes/usage-examples/CountTest.php +++ b/docs/includes/usage-examples/CountTest.php @@ -6,6 +6,8 @@ use App\Models\Movie; use MongoDB\Laravel\Tests\TestCase; +use Illuminate\Database\Query\Builder; +use Illuminate\Support\Facades\DB; class CountTest extends TestCase { diff --git a/docs/includes/usage-examples/DeleteManyTest.php b/docs/includes/usage-examples/DeleteManyTest.php index 6e53601b9..e507b4cf4 100644 --- a/docs/includes/usage-examples/DeleteManyTest.php +++ b/docs/includes/usage-examples/DeleteManyTest.php @@ -6,6 +6,8 @@ use App\Models\Movie; use MongoDB\Laravel\Tests\TestCase; +use Illuminate\Database\Query\Builder; +use Illuminate\Support\Facades\DB; class DeleteManyTest extends TestCase { diff --git a/docs/usage-examples/deleteMany.txt b/docs/usage-examples/deleteMany.txt index 965c14996..22cc8d183 100644 --- a/docs/usage-examples/deleteMany.txt +++ b/docs/usage-examples/deleteMany.txt @@ -26,8 +26,9 @@ method. .. tip:: - To learn more about deleting documents with the {+odm-short+}, see the :ref:`laravel-fundamentals-delete-documents` - section of the Write Operations guide. + To learn more about deleting documents with the {+odm-short+}, see + the :ref:`laravel-fundamentals-delete-documents` section of the Write + Operations guide. Example ------- diff --git a/docs/usage-examples/deleteOne.txt b/docs/usage-examples/deleteOne.txt index 1298255da..83eaba253 100644 --- a/docs/usage-examples/deleteOne.txt +++ b/docs/usage-examples/deleteOne.txt @@ -17,12 +17,20 @@ Delete a Document :depth: 1 :class: singlecol -You can delete a document in a collection by retrieving a single Eloquent model and calling -the ``delete()`` method, or by calling ``delete()`` directly on a query builder. +You can delete a document in a collection by retrieving a single +Eloquent model and calling the ``delete()`` method, or by calling +``delete()`` directly on a query builder. -To delete a document, pass a query filter to the ``where()`` method, sort the matching documents, -and call the ``limit()`` method to retrieve only the first document. Then, delete this matching -document by calling the ``delete()`` method. +To delete a document, pass a query filter to the ``where()`` method, +sort the matching documents, and call the ``limit()`` method to retrieve +only the first document. Then, delete this matching document by calling +the ``delete()`` method. + +.. tip:: + + To learn more about deleting documents with the {+odm-short+}, see + the :ref:`laravel-fundamentals-delete-documents` section of the Write + Operations guide. Example ------- @@ -57,10 +65,3 @@ The example calls the following methods on the ``Movie`` model: Deleted documents: 1 .. include:: /includes/usage-examples/fact-edit-laravel-app.rst - -.. tip:: - - To learn more about deleting documents with the {+odm-short+}, see the `Deleting Models - `__ section of the - Laravel documentation. - From 19ed7aec597de1dd23c63a9999842c0ead838caa Mon Sep 17 00:00:00 2001 From: rustagir Date: Thu, 30 Jan 2025 10:24:25 -0500 Subject: [PATCH 03/21] wip --- .../includes/usage-examples/DeleteOneTest.php | 16 ++- docs/includes/usage-examples/DistinctTest.php | 16 ++- docs/usage-examples/deleteOne.txt | 100 ++++++++++---- docs/usage-examples/distinct.txt | 129 ++++++++++++------ 4 files changed, 189 insertions(+), 72 deletions(-) diff --git a/docs/includes/usage-examples/DeleteOneTest.php b/docs/includes/usage-examples/DeleteOneTest.php index 1a2acd4e0..5209a8020 100644 --- a/docs/includes/usage-examples/DeleteOneTest.php +++ b/docs/includes/usage-examples/DeleteOneTest.php @@ -6,6 +6,8 @@ use App\Models\Movie; use MongoDB\Laravel\Tests\TestCase; +use Illuminate\Database\Query\Builder; +use Illuminate\Support\Facades\DB; class DeleteOneTest extends TestCase { @@ -25,14 +27,24 @@ public function testDeleteOne(): void ], ]); - // begin-delete-one + // begin-eloquent-delete-one $deleted = Movie::where('title', 'Quiz Show') ->orderBy('_id') ->limit(1) ->delete(); echo 'Deleted documents: ' . $deleted; - // end-delete-one + // end-eloquent-delete-one + + // begin-qb-delete-one + $deleted = DB::table('movies') + ->where('title', 'Quiz Show') + ->orderBy('_id') + ->limit(1) + ->delete(); + + echo 'Deleted documents: ' . $deleted; + // end-qb-delete-one $this->assertEquals(1, $deleted); $this->expectOutputString('Deleted documents: 1'); diff --git a/docs/includes/usage-examples/DistinctTest.php b/docs/includes/usage-examples/DistinctTest.php index 0b7812241..4f4946301 100644 --- a/docs/includes/usage-examples/DistinctTest.php +++ b/docs/includes/usage-examples/DistinctTest.php @@ -6,6 +6,8 @@ use App\Models\Movie; use MongoDB\Laravel\Tests\TestCase; +use Illuminate\Database\Query\Builder; +use Illuminate\Support\Facades\DB; class DistinctTest extends TestCase { @@ -45,14 +47,24 @@ public function testDistinct(): void ], ]); - // begin-distinct + // begin-eloquent-distinct $ratings = Movie::where('directors', 'Sofia Coppola') ->select('imdb.rating') ->distinct() ->get(); echo $ratings; - // end-distinct + // end-eloquent-distinct + + // begin-qb-distinct + $ratings = DB::table('movies') + ->where('directors', 'Sofia Coppola') + ->select('imdb.rating') + ->distinct() + ->get(); + + echo $ratings; + // end-qb-distinct $this->expectOutputString('[[6.4],[7.8]]'); } diff --git a/docs/usage-examples/deleteOne.txt b/docs/usage-examples/deleteOne.txt index 83eaba253..940564bd5 100644 --- a/docs/usage-examples/deleteOne.txt +++ b/docs/usage-examples/deleteOne.txt @@ -35,33 +35,77 @@ the ``delete()`` method. Example ------- -This usage example performs the following actions: - -- Uses the ``Movie`` Eloquent model to represent the ``movies`` collection in the - ``sample_mflix`` database -- Deletes a document from the ``movies`` collection that matches a query filter -- Prints the number of deleted documents - -The example calls the following methods on the ``Movie`` model: - -- ``where()``: matches documents in which the value of the ``title`` field is ``"Quiz Show"`` -- ``orderBy()``: sorts matched documents by their ascending ``_id`` values -- ``limit()``: retrieves only the first matching document -- ``delete()``: deletes the retrieved document - -.. io-code-block:: - :copyable: true - - .. input:: ../includes/usage-examples/DeleteOneTest.php - :start-after: begin-delete-one - :end-before: end-delete-one - :language: php - :dedent: - - .. output:: - :language: console - :visible: false - - Deleted documents: 1 +Select from the following :guilabel:`Eloquent` and :guilabel:`Query +Builder` tabs to view usage examples for the same operation that use +each corresponding query syntax: + +.. tabs:: + + .. tab:: Eloquent + :tabid: eloquent-model-count + + This example performs the following actions: + + - Uses the ``Movie`` Eloquent model to represent the ``movies`` + collection in the ``sample_mflix`` database + - Deletes a document from the ``movies`` collection that matches a + query filter + - Prints the number of deleted documents + + The example calls the following methods on the ``Movie`` model: + + - ``where()``: Matches documents in which the value of the + ``title`` field is ``"Quiz Show"`` + - ``orderBy()``: Sorts matched documents by their ascending ``_id`` values + - ``limit()``: Retrieves only the first matching document + - ``delete()``: Deletes the retrieved document + + .. io-code-block:: + :copyable: true + + .. input:: ../includes/usage-examples/DeleteOneTest.php + :start-after: begin-eloquent-delete-one + :end-before: end-eloquent-delete-one + :language: php + :dedent: + + .. output:: + :language: console + :visible: false + + Deleted documents: 1 + + .. tab:: Query Builder + :tabid: query-builder-count + + This example performs the following actions: + + - Accesses the ``movies`` collection by calling the ``table()`` + method from the ``DB`` facade + - Deletes a document from the ``movies`` collection that matches a + query filter + - Prints the number of deleted documents + + The example calls the following query builder methods: + + - ``where()``: Matches documents in which the value of the + ``title`` field is ``"Quiz Show"`` + - ``orderBy()``: Sorts matched documents by their ascending ``_id`` values + - ``limit()``: Retrieves only the first matching document + - ``delete()``: Deletes the retrieved document + + .. io-code-block:: + + .. input:: ../includes/usage-examples/DeleteOneTest.php + :start-after: begin-qb-delete-one + :end-before: end-qb-delete-one + :language: php + :dedent: + + .. output:: + :language: console + :visible: false + + Deleted documents: 1 .. include:: /includes/usage-examples/fact-edit-laravel-app.rst diff --git a/docs/usage-examples/distinct.txt b/docs/usage-examples/distinct.txt index 5d62ec8be..0c826d3e4 100644 --- a/docs/usage-examples/distinct.txt +++ b/docs/usage-examples/distinct.txt @@ -17,50 +17,99 @@ Retrieve Distinct Field Values :depth: 1 :class: singlecol -You can retrieve distinct field values of documents in a collection by calling the ``distinct()`` -method on an object collection or a query builder. +You can retrieve distinct field values of documents in a collection by +calling the ``distinct()`` method on an object collection or a query +builder. -To retrieve distinct field values, pass a query filter to the ``where()`` method and a field name -to the ``select()`` method. Then, call ``distinct()`` to return the unique values of the selected -field in documents that match the query filter. +To retrieve distinct field values, pass a query filter to the +``where()`` method and a field name to the ``select()`` method. Then, +call ``distinct()`` to return the unique values of the selected field in +documents that match the query filter. -Example -------- - -This usage example performs the following actions: - -- Uses the ``Movie`` Eloquent model to represent the ``movies`` collection in the - ``sample_mflix`` database -- Retrieves distinct field values of documents from the ``movies`` collection that match a query filter -- Prints the distinct values - -The example calls the following methods on the ``Movie`` model: - -- ``where()``: matches documents in which the value of the ``directors`` field includes ``"Sofia Coppola"``. -- ``select()``: retrieves the matching documents' ``imdb.rating`` field values. -- ``distinct()``: retrieves the unique values of the selected field and returns - the list of values. -- ``get()``: retrieves the query results. - -.. io-code-block:: - :copyable: true +.. tip:: - .. input:: ../includes/usage-examples/DistinctTest.php - :start-after: begin-distinct - :end-before: end-distinct - :language: php - :dedent: + For more information about query filters, see the + :ref:`laravel-retrieve-matching` section of the Read Operations + guide. - .. output:: - :language: console - :visible: false +Example +------- - [[5.6],[6.4],[7.2],[7.8]] +Select from the following :guilabel:`Eloquent` and :guilabel:`Query +Builder` tabs to view usage examples for the same operation that use +each corresponding query syntax: + +.. tabs:: + + .. tab:: Eloquent + :tabid: eloquent-model-count + + This example performs the following actions: + + - Uses the ``Movie`` Eloquent model to represent the ``movies`` + collection in the ``sample_mflix`` database + - Retrieves distinct field values of documents from the ``movies`` + collection that match a query filter + - Prints the distinct values + + The example calls the following methods on the ``Movie`` model: + + - ``where()``: Matches documents in which the value of the + ``directors`` field includes ``"Sofia Coppola"`` + - ``select()``: Retrieves the matching documents' ``imdb.rating`` + field values + - ``distinct()``: Retrieves the unique values of the selected + field and returns the list of values + - ``get()``: Retrieves the query results + + .. io-code-block:: + :copyable: true + + .. input:: ../includes/usage-examples/DistinctTest.php + :start-after: begin-eloquent-distinct + :end-before: end-eloquent-distinct + :language: php + :dedent: + + .. output:: + :language: console + :visible: false + + [[5.6],[6.4],[7.2],[7.8]] + + .. tab:: Query Builder + :tabid: query-builder-count + + This example performs the following actions: + + - Accesses the ``movies`` collection by calling the ``table()`` + method from the ``DB`` facade + - Retrieves distinct field values of documents from the ``movies`` + collection that match a query filter + - Prints the distinct values + + The example calls the following query builder methods: + + - ``where()``: Matches documents in which the value of the + ``directors`` field includes ``"Sofia Coppola"`` + - ``select()``: Retrieves the matching documents' ``imdb.rating`` + field values + - ``distinct()``: Retrieves the unique values of the selected + field and returns the list of values + - ``get()``: Retrieves the query results + + .. io-code-block:: + + .. input:: ../includes/usage-examples/DistinctTest.php + :start-after: begin-qb-distinct + :end-before: end-qb-distinct + :language: php + :dedent: + + .. output:: + :language: console + :visible: false + + [[5.6],[6.4],[7.2],[7.8]] .. include:: /includes/usage-examples/fact-edit-laravel-app.rst - -.. tip:: - - For more information about query filters, see the :ref:`laravel-retrieve-matching` section of - the Read Operations guide. - From 111b290d463e505390d0eb24bc29160f791817c1 Mon Sep 17 00:00:00 2001 From: rustagir Date: Thu, 30 Jan 2025 10:24:41 -0500 Subject: [PATCH 04/21] formatting --- docs/includes/usage-examples/CountTest.php | 3 +-- docs/includes/usage-examples/DeleteManyTest.php | 3 +-- docs/includes/usage-examples/DeleteOneTest.php | 3 +-- docs/includes/usage-examples/DistinctTest.php | 3 +-- 4 files changed, 4 insertions(+), 8 deletions(-) diff --git a/docs/includes/usage-examples/CountTest.php b/docs/includes/usage-examples/CountTest.php index f7a88d6fd..36609c59c 100644 --- a/docs/includes/usage-examples/CountTest.php +++ b/docs/includes/usage-examples/CountTest.php @@ -5,9 +5,8 @@ namespace App\Http\Controllers; use App\Models\Movie; -use MongoDB\Laravel\Tests\TestCase; -use Illuminate\Database\Query\Builder; use Illuminate\Support\Facades\DB; +use MongoDB\Laravel\Tests\TestCase; class CountTest extends TestCase { diff --git a/docs/includes/usage-examples/DeleteManyTest.php b/docs/includes/usage-examples/DeleteManyTest.php index e507b4cf4..0927ef8fe 100644 --- a/docs/includes/usage-examples/DeleteManyTest.php +++ b/docs/includes/usage-examples/DeleteManyTest.php @@ -5,9 +5,8 @@ namespace App\Http\Controllers; use App\Models\Movie; -use MongoDB\Laravel\Tests\TestCase; -use Illuminate\Database\Query\Builder; use Illuminate\Support\Facades\DB; +use MongoDB\Laravel\Tests\TestCase; class DeleteManyTest extends TestCase { diff --git a/docs/includes/usage-examples/DeleteOneTest.php b/docs/includes/usage-examples/DeleteOneTest.php index 5209a8020..0fe718500 100644 --- a/docs/includes/usage-examples/DeleteOneTest.php +++ b/docs/includes/usage-examples/DeleteOneTest.php @@ -5,9 +5,8 @@ namespace App\Http\Controllers; use App\Models\Movie; -use MongoDB\Laravel\Tests\TestCase; -use Illuminate\Database\Query\Builder; use Illuminate\Support\Facades\DB; +use MongoDB\Laravel\Tests\TestCase; class DeleteOneTest extends TestCase { diff --git a/docs/includes/usage-examples/DistinctTest.php b/docs/includes/usage-examples/DistinctTest.php index 4f4946301..3ff73cdb7 100644 --- a/docs/includes/usage-examples/DistinctTest.php +++ b/docs/includes/usage-examples/DistinctTest.php @@ -5,9 +5,8 @@ namespace App\Http\Controllers; use App\Models\Movie; -use MongoDB\Laravel\Tests\TestCase; -use Illuminate\Database\Query\Builder; use Illuminate\Support\Facades\DB; +use MongoDB\Laravel\Tests\TestCase; class DistinctTest extends TestCase { From a69ed4bdf741d872aa0a322e37e75adfa5ff2ea7 Mon Sep 17 00:00:00 2001 From: rustagir Date: Thu, 30 Jan 2025 11:12:48 -0500 Subject: [PATCH 05/21] wip --- .../usage-examples/DeleteManyTest.php | 6 +- .../includes/usage-examples/DeleteOneTest.php | 6 +- docs/includes/usage-examples/FindManyTest.php | 12 +- docs/includes/usage-examples/FindOneTest.php | 14 +- .../usage-examples/InsertManyTest.php | 25 ++- docs/usage-examples/find.txt | 159 ++++++++++++------ docs/usage-examples/findOne.txt | 134 ++++++++++----- docs/usage-examples/insertMany.txt | 102 +++++++---- 8 files changed, 323 insertions(+), 135 deletions(-) diff --git a/docs/includes/usage-examples/DeleteManyTest.php b/docs/includes/usage-examples/DeleteManyTest.php index 0927ef8fe..433b84895 100644 --- a/docs/includes/usage-examples/DeleteManyTest.php +++ b/docs/includes/usage-examples/DeleteManyTest.php @@ -37,6 +37,9 @@ public function testDeleteMany(): void echo 'Deleted documents: ' . $deleted; // end-eloquent-delete-many + $this->assertEquals(2, $deleted); + $this->expectOutputString('Deleted documents: 2'); + // begin-qb-delete-many $deleted = DB::table('movies') ->where('year', '<=', 1910) @@ -44,8 +47,5 @@ public function testDeleteMany(): void echo 'Deleted documents: ' . $deleted; // end-qb-delete-many - - $this->assertEquals(2, $deleted); - $this->expectOutputString('Deleted documents: 2'); } } diff --git a/docs/includes/usage-examples/DeleteOneTest.php b/docs/includes/usage-examples/DeleteOneTest.php index 0fe718500..037e6b727 100644 --- a/docs/includes/usage-examples/DeleteOneTest.php +++ b/docs/includes/usage-examples/DeleteOneTest.php @@ -35,6 +35,9 @@ public function testDeleteOne(): void echo 'Deleted documents: ' . $deleted; // end-eloquent-delete-one + $this->assertEquals(1, $deleted); + $this->expectOutputString('Deleted documents: 1'); + // begin-qb-delete-one $deleted = DB::table('movies') ->where('title', 'Quiz Show') @@ -44,8 +47,5 @@ public function testDeleteOne(): void echo 'Deleted documents: ' . $deleted; // end-qb-delete-one - - $this->assertEquals(1, $deleted); - $this->expectOutputString('Deleted documents: 1'); } } diff --git a/docs/includes/usage-examples/FindManyTest.php b/docs/includes/usage-examples/FindManyTest.php index 18324c62d..6293e8a8a 100644 --- a/docs/includes/usage-examples/FindManyTest.php +++ b/docs/includes/usage-examples/FindManyTest.php @@ -5,6 +5,7 @@ namespace App\Http\Controllers; use App\Models\Movie; +use Illuminate\Support\Facades\DB; use MongoDB\Laravel\Tests\TestCase; class FindManyTest extends TestCase @@ -33,11 +34,18 @@ public function testFindMany(): void ], ]); - // begin-find + // begin-eloquent-find $movies = Movie::where('runtime', '>', 900) ->orderBy('_id') ->get(); - // end-find + // end-eloquent-find + + // begin-qb-find + $movies = DB::table('movies') + ->where('runtime', '>', 900) + ->orderBy('_id') + ->get(); + // end-qb-find $this->assertEquals(2, $movies->count()); } diff --git a/docs/includes/usage-examples/FindOneTest.php b/docs/includes/usage-examples/FindOneTest.php index 98452a6a6..abcf29f09 100644 --- a/docs/includes/usage-examples/FindOneTest.php +++ b/docs/includes/usage-examples/FindOneTest.php @@ -5,6 +5,7 @@ namespace App\Http\Controllers; use App\Models\Movie; +use Illuminate\Support\Facades\DB; use MongoDB\Laravel\Tests\TestCase; class FindOneTest extends TestCase @@ -22,15 +23,24 @@ public function testFindOne(): void ['title' => 'The Shawshank Redemption', 'directors' => ['Frank Darabont', 'Rob Reiner']], ]); - // begin-find-one + // begin-eloquent-find-one $movie = Movie::where('directors', 'Rob Reiner') ->orderBy('_id') ->first(); echo $movie->toJson(); - // end-find-one + // end-eloquent-find-one $this->assertInstanceOf(Movie::class, $movie); $this->expectOutputRegex('/^{"_id":"[a-z0-9]{24}","title":"The Shawshank Redemption","directors":\["Frank Darabont","Rob Reiner"\]}$/'); + + // begin-qb-find-one + $movie = DB::table('movies') + ->where('directors', 'Rob Reiner') + ->orderBy('_id') + ->first(); + + echo $movie->toJson(); + // end-qb-find-one } } diff --git a/docs/includes/usage-examples/InsertManyTest.php b/docs/includes/usage-examples/InsertManyTest.php index e1bf4539a..2017f754e 100644 --- a/docs/includes/usage-examples/InsertManyTest.php +++ b/docs/includes/usage-examples/InsertManyTest.php @@ -6,6 +6,7 @@ use App\Models\Movie; use DateTimeImmutable; +use Illuminate\Support\Facades\DB; use MongoDB\BSON\UTCDateTime; use MongoDB\Laravel\Tests\TestCase; @@ -21,7 +22,7 @@ public function testInsertMany(): void Movie::truncate(); - // begin-insert-many + // begin-eloquent-insert-many $success = Movie::insert([ [ 'title' => 'Anatomy of a Fall', @@ -38,7 +39,27 @@ public function testInsertMany(): void ]); echo 'Insert operation success: ' . ($success ? 'yes' : 'no'); - // end-insert-many + // end-eloquent-insert-many + + // begin-qb-insert-many + $success = DB::table('movies') + ->insert([ + [ + 'title' => 'Anatomy of a Fall', + 'release_date' => new UTCDateTime(new DateTimeImmutable('2023-08-23')), + ], + [ + 'title' => 'The Boy and the Heron', + 'release_date' => new UTCDateTime(new DateTimeImmutable('2023-12-08')), + ], + [ + 'title' => 'Passages', + 'release_date' => new UTCDateTime(new DateTimeImmutable('2023-06-28')), + ], + ]); + + echo 'Insert operation success: ' . ($success ? 'yes' : 'no'); + // end-qb-insert-many $this->assertTrue($success); $this->expectOutputString('Insert operation success: yes'); diff --git a/docs/usage-examples/find.txt b/docs/usage-examples/find.txt index c70805541..bb9892947 100644 --- a/docs/usage-examples/find.txt +++ b/docs/usage-examples/find.txt @@ -29,62 +29,121 @@ Find Multiple Documents Pass a query filter to the ``where()`` method to retrieve documents that meet a set of criteria. When you call the ``get()`` method, MongoDB returns the -matching documents according to their :term:`natural order` in the database or +matching documents according to their :term:`natural order` in the collection or according to the sort order that you can specify by using the ``orderBy()`` method. -To learn more about query builder methods, see the :ref:`laravel-query-builder` -guide. +.. tip:: + + To learn about other ways to retrieve documents with the + {+odm-short+}, see the :ref:`laravel-fundamentals-retrieve` guide. Example ------- -This usage example performs the following actions: - -- Uses the ``Movie`` Eloquent model to represent the ``movies`` collection in the - ``sample_mflix`` database -- Retrieves and prints documents from the ``movies`` collection that match a query filter - -The example calls the following methods on the ``Movie`` model: - -- ``where()``: matches documents in which the value of the ``runtime`` field is greater than ``900`` -- ``orderBy()``: sorts matched documents by their ascending ``_id`` values -- ``get()``: retrieves the query results as a Laravel collection object - -.. io-code-block:: - :copyable: true - - .. input:: ../includes/usage-examples/FindManyTest.php - :start-after: begin-find - :end-before: end-find - :language: php - :dedent: - - .. output:: - :language: json - :visible: false - - // Results are truncated - - [ - { - "_id": ..., - "runtime": 1256, - "title": "Centennial", - ..., - }, - { - "_id": ..., - "runtime": 1140, - "title": "Baseball", - ..., - }, - ... - ] +Select from the following :guilabel:`Eloquent` and :guilabel:`Query +Builder` tabs to view usage examples for the same operation that use +each corresponding query syntax: + +.. tabs:: + + .. tab:: Eloquent + :tabid: eloquent-model-count + + This example performs the following actions: + + - Uses the ``Movie`` Eloquent model to represent the ``movies`` + collection in the ``sample_mflix`` database + - Retrieves and prints documents from the ``movies`` collection + that match a query filter + + The example calls the following methods on the ``Movie`` model: + + - ``where()``: Matches documents in which the value of the + ``runtime`` field is greater than ``900`` + - ``orderBy()``: Sorts matched documents by their ascending + ``_id`` values + - ``get()``: Retrieves the query results as a Laravel collection + object + + .. io-code-block:: + :copyable: true + + .. input:: ../includes/usage-examples/FindManyTest.php + :start-after: begin-eloquent-find + :end-before: end-eloquent-find + :language: php + :dedent: + + .. output:: + :language: console + :visible: false + + // Results are truncated + + [ + { + "_id": ..., + "runtime": 1256, + "title": "Centennial", + ..., + }, + { + "_id": ..., + "runtime": 1140, + "title": "Baseball", + ..., + }, + ... + ] + + .. tab:: Query Builder + :tabid: query-builder-count + + This example performs the following actions: + + - Accesses the ``movies`` collection by calling the ``table()`` + method from the ``DB`` facade + - Retrieves and prints documents from the ``movies`` collection + that match a query filter + + The example calls the following query builder methods: + + - ``where()``: Matches documents in which the value of the + ``runtime`` field is greater than ``900`` + - ``orderBy()``: Sorts matched documents by their ascending + ``_id`` values + - ``get()``: Retrieves the query results as a Laravel collection + object + + .. io-code-block:: + + .. input:: ../includes/usage-examples/FindManyTest.php + :start-after: begin-qb-find + :end-before: end-qb-find + :language: php + :dedent: + + .. output:: + :language: console + :visible: false + + // Results are truncated + + [ + { + "_id": ..., + "runtime": 1256, + "title": "Centennial", + ..., + }, + { + "_id": ..., + "runtime": 1140, + "title": "Baseball", + ..., + }, + ... + ] .. include:: /includes/usage-examples/fact-edit-laravel-app.rst - -.. tip:: - - To learn about other ways to retrieve documents with the {+odm-short+}, see the - :ref:`laravel-fundamentals-retrieve` guide. diff --git a/docs/usage-examples/findOne.txt b/docs/usage-examples/findOne.txt index 2b3109152..8995f02d4 100644 --- a/docs/usage-examples/findOne.txt +++ b/docs/usage-examples/findOne.txt @@ -21,50 +21,102 @@ Find a Document the ``first()`` method to return one document -If multiple documents match the query filter, ``first()`` returns the first matching document according to the documents' -:term:`natural order` in the database or according to the sort order that you can specify -by using the ``orderBy()`` method. +If multiple documents match the query filter, ``first()`` returns the +first matching document according to the documents' :term:`natural +order` in the database or according to the sort order that you can +specify by using the ``orderBy()`` method. -Example -------- - -This usage example performs the following actions: - -- Uses the ``Movie`` Eloquent model to represent the ``movies`` collection in the - ``sample_mflix`` database -- Retrieves a document from the ``movies`` collection that matches a query filter -- Prints the retrieved document - -The example calls the following methods on the ``Movie`` model: - -- ``where()``: matches documents in which the value of the ``directors`` field includes ``"Rob Reiner"``. -- ``orderBy()``: sorts matched documents by their ascending ``_id`` values. -- ``first()``: retrieves only the first matching document. - -.. io-code-block:: - - .. input:: ../includes/usage-examples/FindOneTest.php - :start-after: begin-find-one - :end-before: end-find-one - :language: php - :dedent: +.. tip:: - .. output:: - :language: console - :visible: false + To learn about other ways to retrieve documents with the + {+odm-short+}, see the :ref:`laravel-fundamentals-retrieve` guide. - // Result is truncated +Example +------- - { - "_id": ..., - "title": "This Is Spinal Tap", - "directors": [ "Rob Reiner" ], - ... - } +Select from the following :guilabel:`Eloquent` and :guilabel:`Query +Builder` tabs to view usage examples for the same operation that use +each corresponding query syntax: + +.. tabs:: + + .. tab:: Eloquent + :tabid: eloquent-model-count + + This example performs the following actions: + + - Uses the ``Movie`` Eloquent model to represent the ``movies`` + collection in the ``sample_mflix`` database + - Retrieves a document from the ``movies`` collection that matches + a query filter + - Prints the retrieved document + + The example calls the following methods on the ``Movie`` model: + + - ``where()``: Matches documents in which the value of the + ``directors`` field includes ``"Rob Reiner"`` + - ``orderBy()``: Sorts matched documents by their ascending ``_id`` values + - ``first()``: Retrieves only the first matching document + + .. io-code-block:: + :copyable: true + + .. input:: ../includes/usage-examples/FindOneTest.php + :start-after: begin-eloquent-find-one + :end-before: end-eloquent-find-one + :language: php + :dedent: + + .. output:: + :language: console + :visible: false + + // Result is truncated + + { + "_id": ..., + "title": "This Is Spinal Tap", + "directors": [ "Rob Reiner" ], + ... + } + + .. tab:: Query Builder + :tabid: query-builder-count + + This example performs the following actions: + + - Accesses the ``movies`` collection by calling the ``table()`` + method from the ``DB`` facade + - Retrieves a document from the ``movies`` collection that matches + a query filter + - Prints the retrieved document + + The example calls the following query builder methods: + + - ``where()``: Matches documents in which the value of the + ``directors`` field includes ``"Rob Reiner"`` + - ``orderBy()``: Sorts matched documents by their ascending ``_id`` values + - ``first()``: Retrieves only the first matching document + + .. io-code-block:: + + .. input:: ../includes/usage-examples/FindOneTest.php + :start-after: begin-qb-find-one + :end-before: end-qb-find-one + :language: php + :dedent: + + .. output:: + :language: console + :visible: false + + // Result is truncated + + { + "_id": ..., + "title": "This Is Spinal Tap", + "directors": [ "Rob Reiner" ], + ... + } .. include:: /includes/usage-examples/fact-edit-laravel-app.rst - -.. tip:: - - To learn more about retrieving documents with the {+odm-short+}, see the - :ref:`laravel-fundamentals-retrieve` guide. diff --git a/docs/usage-examples/insertMany.txt b/docs/usage-examples/insertMany.txt index 2d59a78ab..9d3a16b3e 100644 --- a/docs/usage-examples/insertMany.txt +++ b/docs/usage-examples/insertMany.txt @@ -24,40 +24,78 @@ To insert multiple documents, call the ``insert()`` method and specify the new d as an array inside the method call. Each array entry contains a single document's field values. -Example -------- - -This usage example performs the following actions: - -- Uses the ``Movie`` Eloquent model to represent the ``movies`` collection in the - ``sample_mflix`` database -- Inserts documents into the ``movies`` collection -- Prints whether the insert operation succeeds - -The example calls the ``insert()`` method to insert documents that contain -information about movies released in ``2023``. If the insert operation is -successful, it returns a value of ``1``. If the operation fails, it throws -an exception. - -.. io-code-block:: - :copyable: true +.. tip:: - .. input:: ../includes/usage-examples/InsertManyTest.php - :start-after: begin-insert-many - :end-before: end-insert-many - :language: php - :dedent: + To learn more about insert operations, see the + :ref:`laravel-fundamentals-insert-documents` section + of the Write Operations guide. - .. output:: - :language: console - :visible: false +Example +------- - Insert operation success: yes +Select from the following :guilabel:`Eloquent` and :guilabel:`Query +Builder` tabs to view usage examples for the same operation that use +each corresponding query syntax: + +.. tabs:: + + .. tab:: Eloquent + :tabid: eloquent-model-count + + This example performs the following actions: + + - Uses the ``Movie`` Eloquent model to represent the ``movies`` + collection in the ``sample_mflix`` database + - Inserts documents into the ``movies`` collection + - Prints whether the insert operation succeeds + + The example calls the ``insert()`` method to insert documents that model + movies released in ``2023``. If the insert operation is + successful, it returns a value of ``1``. If the operation fails, it throws + an exception. + + .. io-code-block:: + :copyable: true + + .. input:: ../includes/usage-examples/InsertManyTest.php + :start-after: begin-eloquent-insert-many + :end-before: end-eloquent-insert-many + :language: php + :dedent: + + .. output:: + :language: console + :visible: false + + Insert operation success: yes + + .. tab:: Query Builder + :tabid: query-builder-count + + This example performs the following actions: + + - Accesses the ``movies`` collection by calling the ``table()`` + method from the ``DB`` facade + - Inserts documents into the ``movies`` collection + - Prints whether the insert operation succeeds + + The example calls the ``insert()`` method to insert documents that model + movies released in ``2023``. If the insert operation is + successful, it returns a value of ``1``. If the operation fails, it throws + an exception. + + .. io-code-block:: + + .. input:: ../includes/usage-examples/InsertManyTest.php + :start-after: begin-qb-insert-many + :end-before: end-qb-insert-many + :language: php + :dedent: + + .. output:: + :language: console + :visible: false + + Insert operation success: yes .. include:: /includes/usage-examples/fact-edit-laravel-app.rst - -.. tip:: - - To learn more about insert operations, see the :ref:`laravel-fundamentals-insert-documents` section - of the Write Operations guide. - From 6c93d6dae086657d07a0f0949b0500816f253c00 Mon Sep 17 00:00:00 2001 From: rustagir Date: Thu, 30 Jan 2025 13:20:22 -0500 Subject: [PATCH 06/21] fix tests? --- docs/includes/usage-examples/CountTest.php | 2 +- docs/includes/usage-examples/DeleteManyTest.php | 2 +- docs/includes/usage-examples/DeleteOneTest.php | 2 +- docs/includes/usage-examples/DistinctTest.php | 2 +- docs/includes/usage-examples/FindOneTest.php | 2 +- docs/includes/usage-examples/InsertManyTest.php | 2 +- docs/usage-examples/distinct.txt | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/docs/includes/usage-examples/CountTest.php b/docs/includes/usage-examples/CountTest.php index 36609c59c..b3cbc01e1 100644 --- a/docs/includes/usage-examples/CountTest.php +++ b/docs/includes/usage-examples/CountTest.php @@ -46,6 +46,6 @@ public function testCount(): void // end-qb-count $this->assertEquals(2, $count); - $this->expectOutputString('Number of documents: 2'); + $this->expectOutputString('Number of documents: 2Number of documents: 2'); } } diff --git a/docs/includes/usage-examples/DeleteManyTest.php b/docs/includes/usage-examples/DeleteManyTest.php index 433b84895..638423776 100644 --- a/docs/includes/usage-examples/DeleteManyTest.php +++ b/docs/includes/usage-examples/DeleteManyTest.php @@ -38,7 +38,7 @@ public function testDeleteMany(): void // end-eloquent-delete-many $this->assertEquals(2, $deleted); - $this->expectOutputString('Deleted documents: 2'); + $this->expectOutputString('Deleted documents: 2Deleted documents: 0'); // begin-qb-delete-many $deleted = DB::table('movies') diff --git a/docs/includes/usage-examples/DeleteOneTest.php b/docs/includes/usage-examples/DeleteOneTest.php index 037e6b727..71fecf033 100644 --- a/docs/includes/usage-examples/DeleteOneTest.php +++ b/docs/includes/usage-examples/DeleteOneTest.php @@ -36,7 +36,7 @@ public function testDeleteOne(): void // end-eloquent-delete-one $this->assertEquals(1, $deleted); - $this->expectOutputString('Deleted documents: 1'); + $this->expectOutputString('Deleted documents: 1Deleted documents: 0'); // begin-qb-delete-one $deleted = DB::table('movies') diff --git a/docs/includes/usage-examples/DistinctTest.php b/docs/includes/usage-examples/DistinctTest.php index 3ff73cdb7..35a0e63ce 100644 --- a/docs/includes/usage-examples/DistinctTest.php +++ b/docs/includes/usage-examples/DistinctTest.php @@ -65,6 +65,6 @@ public function testDistinct(): void echo $ratings; // end-qb-distinct - $this->expectOutputString('[[6.4],[7.8]]'); + $this->expectOutputString('[[6.4],[7.8]][6.4,7.8]'); } } diff --git a/docs/includes/usage-examples/FindOneTest.php b/docs/includes/usage-examples/FindOneTest.php index abcf29f09..e6f370f43 100644 --- a/docs/includes/usage-examples/FindOneTest.php +++ b/docs/includes/usage-examples/FindOneTest.php @@ -40,7 +40,7 @@ public function testFindOne(): void ->orderBy('_id') ->first(); - echo $movie->toJson(); + echo $movie; // end-qb-find-one } } diff --git a/docs/includes/usage-examples/InsertManyTest.php b/docs/includes/usage-examples/InsertManyTest.php index 2017f754e..85ba50f36 100644 --- a/docs/includes/usage-examples/InsertManyTest.php +++ b/docs/includes/usage-examples/InsertManyTest.php @@ -62,6 +62,6 @@ public function testInsertMany(): void // end-qb-insert-many $this->assertTrue($success); - $this->expectOutputString('Insert operation success: yes'); + $this->expectOutputString('Insert operation success: yesInsert operation success: yes'); } } diff --git a/docs/usage-examples/distinct.txt b/docs/usage-examples/distinct.txt index 0c826d3e4..cfe1e4644 100644 --- a/docs/usage-examples/distinct.txt +++ b/docs/usage-examples/distinct.txt @@ -110,6 +110,6 @@ each corresponding query syntax: :language: console :visible: false - [[5.6],[6.4],[7.2],[7.8]] + [5.6,6.4,7.2,7.8] .. include:: /includes/usage-examples/fact-edit-laravel-app.rst From 7cb0b1207e0d8c6198821321b76cb1bc1644a3b6 Mon Sep 17 00:00:00 2001 From: rustagir Date: Thu, 30 Jan 2025 13:28:54 -0500 Subject: [PATCH 07/21] fix tests? --- docs/includes/usage-examples/FindOneTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/includes/usage-examples/FindOneTest.php b/docs/includes/usage-examples/FindOneTest.php index e6f370f43..42510a4af 100644 --- a/docs/includes/usage-examples/FindOneTest.php +++ b/docs/includes/usage-examples/FindOneTest.php @@ -40,7 +40,7 @@ public function testFindOne(): void ->orderBy('_id') ->first(); - echo $movie; + echo $movie[0]->toJson(); // end-qb-find-one } } From f498f97c3cfacab9c4be7a274a58a0083b6ca076 Mon Sep 17 00:00:00 2001 From: rustagir Date: Thu, 30 Jan 2025 14:26:16 -0500 Subject: [PATCH 08/21] wip --- docs/includes/usage-examples/FindOneTest.php | 4 +- .../includes/usage-examples/InsertOneTest.php | 18 ++- .../usage-examples/UpdateManyTest.php | 16 ++- .../includes/usage-examples/UpdateOneTest.php | 23 +++- docs/usage-examples/insertOne.txt | 122 ++++++++++++------ docs/usage-examples/updateMany.txt | 112 +++++++++++----- docs/usage-examples/updateOne.txt | 116 ++++++++++++----- 7 files changed, 288 insertions(+), 123 deletions(-) diff --git a/docs/includes/usage-examples/FindOneTest.php b/docs/includes/usage-examples/FindOneTest.php index 42510a4af..014611b85 100644 --- a/docs/includes/usage-examples/FindOneTest.php +++ b/docs/includes/usage-examples/FindOneTest.php @@ -32,7 +32,7 @@ public function testFindOne(): void // end-eloquent-find-one $this->assertInstanceOf(Movie::class, $movie); - $this->expectOutputRegex('/^{"_id":"[a-z0-9]{24}","title":"The Shawshank Redemption","directors":\["Frank Darabont","Rob Reiner"\]}$/'); + $this->assertSame($movie->title, 'The Shawshank Redemption'); // begin-qb-find-one $movie = DB::table('movies') @@ -40,7 +40,7 @@ public function testFindOne(): void ->orderBy('_id') ->first(); - echo $movie[0]->toJson(); + echo print_r($movie); // end-qb-find-one } } diff --git a/docs/includes/usage-examples/InsertOneTest.php b/docs/includes/usage-examples/InsertOneTest.php index 15eadf419..33f0e4d00 100644 --- a/docs/includes/usage-examples/InsertOneTest.php +++ b/docs/includes/usage-examples/InsertOneTest.php @@ -5,6 +5,7 @@ namespace App\Http\Controllers; use App\Models\Movie; +use Illuminate\Support\Facades\DB; use MongoDB\Laravel\Tests\TestCase; class InsertOneTest extends TestCase @@ -19,7 +20,7 @@ public function testInsertOne(): void Movie::truncate(); - // begin-insert-one + // begin-eloquent-insert-one $movie = Movie::create([ 'title' => 'Marriage Story', 'year' => 2019, @@ -27,9 +28,20 @@ public function testInsertOne(): void ]); echo $movie->toJson(); - // end-insert-one + // end-eloquent-insert-one + + // begin-qb-insert-one + $success = DB::table('movies') + ->insert([ + 'title' => 'Marriage Story', + 'year' => 2019, + 'runtime' => 136, + ]); + + echo 'Insert operation success: ' . ($success ? 'yes' : 'no'); + // end-qb-insert-one $this->assertInstanceOf(Movie::class, $movie); - $this->expectOutputRegex('/^{"title":"Marriage Story","year":2019,"runtime":136,"updated_at":".{27}","created_at":".{27}","_id":"[a-z0-9]{24}"}$/'); + $this->assertSame($movie->title, 'Marriage Story'); } } diff --git a/docs/includes/usage-examples/UpdateManyTest.php b/docs/includes/usage-examples/UpdateManyTest.php index 49a77dd95..897afe706 100644 --- a/docs/includes/usage-examples/UpdateManyTest.php +++ b/docs/includes/usage-examples/UpdateManyTest.php @@ -5,6 +5,7 @@ namespace App\Http\Controllers; use App\Models\Movie; +use Illuminate\Support\Facades\DB; use MongoDB\Laravel\Tests\TestCase; class UpdateManyTest extends TestCase @@ -35,14 +36,23 @@ public function testUpdateMany(): void ], ]); - // begin-update-many + // begin-eloquent-update-many $updates = Movie::where('imdb.rating', '>', 9.0) ->update(['acclaimed' => true]); echo 'Updated documents: ' . $updates; - // end-update-many + // end-eloquent-update-many $this->assertEquals(2, $updates); - $this->expectOutputString('Updated documents: 2'); + + // begin-qb-update-many + $updates = DB::table('movies') + ->where('imdb.rating', '>', 9.0) + ->update(['acclaimed' => true]); + + echo 'Updated documents: ' . $updates; + // end-qb-update-many + + $this->expectOutputString('Updated documents: 2Updated documents: 0'); } } diff --git a/docs/includes/usage-examples/UpdateOneTest.php b/docs/includes/usage-examples/UpdateOneTest.php index e1f864170..847643ff5 100644 --- a/docs/includes/usage-examples/UpdateOneTest.php +++ b/docs/includes/usage-examples/UpdateOneTest.php @@ -5,6 +5,7 @@ namespace App\Http\Controllers; use App\Models\Movie; +use Illuminate\Support\Facades\DB; use MongoDB\Laravel\Tests\TestCase; class UpdateOneTest extends TestCase @@ -28,7 +29,7 @@ public function testUpdateOne(): void ], ]); - // begin-update-one + // begin-eloquent-update-one $updates = Movie::where('title', 'Carol') ->orderBy('_id') ->first() @@ -40,9 +41,25 @@ public function testUpdateOne(): void ]); echo 'Updated documents: ' . $updates; - // end-update-one + // end-eloquent-update-one $this->assertTrue($updates); - $this->expectOutputString('Updated documents: 1'); + + // begin-qb-update-one + $updates = DB::table('movies') + ->where('title', 'Carol') + ->orderBy('_id') + ->first() + ->update([ + 'imdb' => [ + 'rating' => 7.3, + 'votes' => 142000, + ], + ]); + + echo 'Updated documents: ' . $updates; + // end-qb-update-one + + $this->expectOutputString('Updated documents: 1Updated documents: 0'); } } diff --git a/docs/usage-examples/insertOne.txt b/docs/usage-examples/insertOne.txt index e28e12090..5bd059840 100644 --- a/docs/usage-examples/insertOne.txt +++ b/docs/usage-examples/insertOne.txt @@ -23,50 +23,88 @@ an Eloquent model or query builder. To insert a document, pass the data you need to insert as a document containing the fields and values to the ``create()`` method. -Example -------- - -This usage example performs the following actions: - -- Uses the ``Movie`` Eloquent model to represent the ``movies`` collection in the - ``sample_mflix`` database -- Inserts a document into the ``movies`` collection - -The example calls the ``create()`` method to insert a document that contains the following -information: - -- ``title`` value of ``"Marriage Story"`` -- ``year`` value of ``2019`` -- ``runtime`` value of ``136`` - -.. io-code-block:: - :copyable: true +.. tip:: - .. input:: ../includes/usage-examples/InsertOneTest.php - :start-after: begin-insert-one - :end-before: end-insert-one - :language: php - :dedent: + You can also use the ``save()`` or ``insert()`` methods to insert a + document into a collection. To learn more about insert operations, + see the :ref:`laravel-fundamentals-insert-documents` section of the + Write Operations guide. - .. output:: - :language: json - :visible: false +Example +------- - { - "title": "Marriage Story", - "year": 2019, - "runtime": 136, - "updated_at": "...", - "created_at": "...", - "_id": "..." - } +Select from the following :guilabel:`Eloquent` and :guilabel:`Query +Builder` tabs to view usage examples for the same operation that use +each corresponding query syntax: + +.. tabs:: + + .. tab:: Eloquent + :tabid: eloquent-model-count + + This example performs the following actions: + + - Uses the ``Movie`` Eloquent model to represent the ``movies`` + collection in the ``sample_mflix`` database + - Inserts a document into the ``movies`` collection + + The example calls the ``create()`` method to insert a document + that contains the following fields and values: + + - ``title`` value of ``"Marriage Story"`` + - ``year`` value of ``2019`` + - ``runtime`` value of ``136`` + + .. io-code-block:: + :copyable: true + + .. input:: ../includes/usage-examples/InsertOneTest.php + :start-after: begin-eloquent-insert-one + :end-before: end-eloquent-insert-one + :language: php + :dedent: + + .. output:: + :language: console + :visible: false + + { + "title": "Marriage Story", + "year": 2019, + "runtime": 136, + "updated_at": "...", + "created_at": "...", + "_id": "..." + } + + .. tab:: Query Builder + :tabid: query-builder-count + + This example performs the following actions: + + - Accesses the ``movies`` collection by calling the ``table()`` + method from the ``DB`` facade + - Inserts a document into the ``movies`` collection + + The example calls the ``create()`` method to insert a document + that contains the following fields and values: + + - ``title`` value of ``"Marriage Story"`` + - ``year`` value of ``2019`` + - ``runtime`` value of ``136`` + + .. io-code-block:: + + .. input:: ../includes/usage-examples/InsertOneTest.php + :start-after: begin-qb-insert-one + :end-before: end-qb-insert-one + :language: php + :dedent: + + .. output:: + :language: console + :visible: false + + Insert operation success: yes .. include:: /includes/usage-examples/fact-edit-laravel-app.rst - -.. tip:: - - You can also use the ``save()`` or ``insert()`` methods to insert a document into a collection. - To learn more about insert operations, see the :ref:`laravel-fundamentals-insert-documents` section - of the Write Operations guide. - - diff --git a/docs/usage-examples/updateMany.txt b/docs/usage-examples/updateMany.txt index 89c262da7..c2c83ce1c 100644 --- a/docs/usage-examples/updateMany.txt +++ b/docs/usage-examples/updateMany.txt @@ -24,43 +24,85 @@ Pass a query filter to the ``where()`` method to retrieve documents that meet a set of criteria. Then, update the matching documents by passing your intended document changes to the ``update()`` method. -Example -------- - -This usage example performs the following actions: - -- Uses the ``Movie`` Eloquent model to represent the ``movies`` collection in the - ``sample_mflix`` database -- Updates documents from the ``movies`` collection that match a query filter -- Prints the number of updated documents - -The example calls the following methods on the ``Movie`` model: - -- ``where()``: matches documents in which the value of the ``imdb.rating`` nested field - is greater than ``9.0``. -- ``update()``: updates the matching documents by adding an ``acclaimed`` field and setting - its value to ``true``. This method returns the number of documents that were successfully - updated. - -.. io-code-block:: - :copyable: true - - .. input:: ../includes/usage-examples/UpdateManyTest.php - :start-after: begin-update-many - :end-before: end-update-many - :language: php - :dedent: - - .. output:: - :language: console - :visible: false - - Updated documents: 20 - -.. include:: /includes/usage-examples/fact-edit-laravel-app.rst - .. tip:: To learn more about updating data with the {+odm-short+}, see the :ref:`laravel-fundamentals-modify-documents` section of the Write Operations guide. +Example +------- + +Select from the following :guilabel:`Eloquent` and :guilabel:`Query +Builder` tabs to view usage examples for the same operation that use +each corresponding query syntax: + +.. tabs:: + + .. tab:: Eloquent + :tabid: eloquent-model-count + + This example performs the following actions: + + - Uses the ``Movie`` Eloquent model to represent the ``movies`` + collection in the ``sample_mflix`` database + - Updates documents from the ``movies`` collection that match a + query filter + - Prints the number of updated documents + + The example calls the following methods on the ``Movie`` model: + + - ``where()``: Matches documents in which the value of the + ``imdb.rating`` nested field is greater than ``9.0`` + - ``update()``: Updates the matching documents by adding an + ``acclaimed`` field and setting its value to ``true``, then + returns the number of updated documents + + .. io-code-block:: + :copyable: true + + .. input:: ../includes/usage-examples/UpdateManyTest.php + :start-after: begin-eloquent-update-many + :end-before: end-eloquent-update-many + :language: php + :dedent: + + .. output:: + :language: console + :visible: false + + Updated documents: 20 + + .. tab:: Query Builder + :tabid: query-builder-count + + This example performs the following actions: + + - Accesses the ``movies`` collection by calling the ``table()`` + method from the ``DB`` facade + - Updates documents from the ``movies`` collection that match a + query filter + - Prints the number of updated documents + + The example calls the following query builder methods: + + - ``where()``: Matches documents in which the value of the + ``imdb.rating`` nested field is greater than ``9.0`` + - ``update()``: Updates the matching documents by adding an + ``acclaimed`` field and setting its value to ``true``, then + returns the number of updated documents + + .. io-code-block:: + + .. input:: ../includes/usage-examples/UpdateManyTest.php + :start-after: begin-qb-update-many + :end-before: end-qb-update-many + :language: php + :dedent: + + .. output:: + :language: console + :visible: false + + Updated documents: 20 + +.. include:: /includes/usage-examples/fact-edit-laravel-app.rst diff --git a/docs/usage-examples/updateOne.txt b/docs/usage-examples/updateOne.txt index ecdc8982d..9470b4a5d 100644 --- a/docs/usage-examples/updateOne.txt +++ b/docs/usage-examples/updateOne.txt @@ -24,43 +24,89 @@ Pass a query filter to the ``where()`` method, sort the matching documents, and ``first()`` method to retrieve only the first document. Then, update this matching document by passing your intended document changes to the ``update()`` method. -Example -------- - -This usage example performs the following actions: - -- Uses the ``Movie`` Eloquent model to represent the ``movies`` collection in the - ``sample_mflix`` database -- Updates a document from the ``movies`` collection that matches the query filter -- Prints the number of updated documents - -The example calls the following methods on the ``Movie`` model: - -- ``where()``: matches documents in which the value of the ``title`` field is ``"Carol"``. -- ``orderBy()``: sorts matched documents by their ascending ``_id`` values. -- ``first()``: retrieves only the first matching document. -- ``update()``: updates the value of the ``imdb.rating`` nested field to from ``6.9`` to - ``7.3`` and the value of the ``imdb.votes`` nested field from ``493`` to ``142000``. - -.. io-code-block:: - :copyable: true - - .. input:: ../includes/usage-examples/UpdateOneTest.php - :start-after: begin-update-one - :end-before: end-update-one - :language: php - :dedent: - - .. output:: - :language: console - :visible: false - - Updated documents: 1 - -.. include:: /includes/usage-examples/fact-edit-laravel-app.rst - .. tip:: To learn more about updating data with the {+odm-short+}, see the :ref:`laravel-fundamentals-modify-documents` section of the Write Operations guide. +Example +------- + +Select from the following :guilabel:`Eloquent` and :guilabel:`Query +Builder` tabs to view usage examples for the same operation that use +each corresponding query syntax: + +.. tabs:: + + .. tab:: Eloquent + :tabid: eloquent-model-count + + This example performs the following actions: + + - Uses the ``Movie`` Eloquent model to represent the ``movies`` + collection in the ``sample_mflix`` database + - Updates a document from the ``movies`` collection that matches + the query filter + - Prints the number of updated documents + + The example calls the following methods on the ``Movie`` model: + + - ``where()``: Matches documents in which the value of the + ``title`` field is ``"Carol"`` + - ``orderBy()``: Sorts matched documents by their ascending ``_id`` values + - ``first()``: Retrieves only the first matching document. + - ``update()``: Updates the value of the ``imdb.rating`` nested + field to from ``6.9`` to ``7.3`` and the value of the + ``imdb.votes`` nested field from ``493`` to ``142000`` + + .. io-code-block:: + :copyable: true + + .. input:: ../includes/usage-examples/UpdateOneTest.php + :start-after: begin-eloquent-update-one + :end-before: end-eloquent-update-one + :language: php + :dedent: + + .. output:: + :language: console + :visible: false + + Updated documents: 1 + + .. tab:: Query Builder + :tabid: query-builder-count + + This example performs the following actions: + + - Accesses the ``movies`` collection by calling the ``table()`` + method from the ``DB`` facade + - Updates a document from the ``movies`` collection that matches + the query filter + - Prints the number of updated documents + + The example calls the following query builder methods: + + - ``where()``: Matches documents in which the value of the + ``title`` field is ``"Carol"`` + - ``orderBy()``: Sorts matched documents by their ascending ``_id`` values + - ``first()``: Retrieves only the first matching document. + - ``update()``: Updates the value of the ``imdb.rating`` nested + field to from ``6.9`` to ``7.3`` and the value of the + ``imdb.votes`` nested field from ``493`` to ``142000`` + + .. io-code-block:: + + .. input:: ../includes/usage-examples/UpdateOneTest.php + :start-after: begin-qb-update-one + :end-before: end-qb-update-one + :language: php + :dedent: + + .. output:: + :language: console + :visible: false + + Updated documents: 1 + +.. include:: /includes/usage-examples/fact-edit-laravel-app.rst From 151bbaa66c0faf029bd3308974ce78a581e3a7ab Mon Sep 17 00:00:00 2001 From: rustagir Date: Thu, 30 Jan 2025 16:29:24 -0500 Subject: [PATCH 09/21] wip --- docs/includes/usage-examples/FindOneTest.php | 2 ++ docs/includes/usage-examples/InsertOneTest.php | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/includes/usage-examples/FindOneTest.php b/docs/includes/usage-examples/FindOneTest.php index 014611b85..04932fa7f 100644 --- a/docs/includes/usage-examples/FindOneTest.php +++ b/docs/includes/usage-examples/FindOneTest.php @@ -8,6 +8,8 @@ use Illuminate\Support\Facades\DB; use MongoDB\Laravel\Tests\TestCase; +use function print_r; + class FindOneTest extends TestCase { /** diff --git a/docs/includes/usage-examples/InsertOneTest.php b/docs/includes/usage-examples/InsertOneTest.php index 33f0e4d00..36517e888 100644 --- a/docs/includes/usage-examples/InsertOneTest.php +++ b/docs/includes/usage-examples/InsertOneTest.php @@ -36,7 +36,7 @@ public function testInsertOne(): void 'title' => 'Marriage Story', 'year' => 2019, 'runtime' => 136, - ]); + ]); echo 'Insert operation success: ' . ($success ? 'yes' : 'no'); // end-qb-insert-one From 0ebad3eae2b1b7ec8580f8a7b864610a5a360f8f Mon Sep 17 00:00:00 2001 From: rustagir Date: Fri, 31 Jan 2025 09:15:10 -0500 Subject: [PATCH 10/21] wip: --- docs/includes/usage-examples/FindOneTest.php | 7 ++++--- docs/includes/usage-examples/UpdateOneTest.php | 18 +++++++++--------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/docs/includes/usage-examples/FindOneTest.php b/docs/includes/usage-examples/FindOneTest.php index 04932fa7f..ee36f6fc5 100644 --- a/docs/includes/usage-examples/FindOneTest.php +++ b/docs/includes/usage-examples/FindOneTest.php @@ -34,15 +34,16 @@ public function testFindOne(): void // end-eloquent-find-one $this->assertInstanceOf(Movie::class, $movie); - $this->assertSame($movie->title, 'The Shawshank Redemption'); - + // begin-qb-find-one $movie = DB::table('movies') ->where('directors', 'Rob Reiner') ->orderBy('_id') ->first(); - echo print_r($movie); + echo $movie['title']; // end-qb-find-one + + $this->assertSame($movie['title'], 'The Shawshank Redemption'); } } diff --git a/docs/includes/usage-examples/UpdateOneTest.php b/docs/includes/usage-examples/UpdateOneTest.php index 847643ff5..6b4f417b1 100644 --- a/docs/includes/usage-examples/UpdateOneTest.php +++ b/docs/includes/usage-examples/UpdateOneTest.php @@ -47,15 +47,15 @@ public function testUpdateOne(): void // begin-qb-update-one $updates = DB::table('movies') - ->where('title', 'Carol') - ->orderBy('_id') - ->first() - ->update([ - 'imdb' => [ - 'rating' => 7.3, - 'votes' => 142000, - ], - ]); + ->updateOne( + ['title' => 'Carol'], + ['$set' => [ + 'imdb' => [ + 'rating' => 7.3, + 'votes' => 142000, + ], + ]] + ); echo 'Updated documents: ' . $updates; // end-qb-update-one From 79035d5c6b2fbea05510439f2d9ab98954c0801d Mon Sep 17 00:00:00 2001 From: rustagir Date: Fri, 31 Jan 2025 09:15:25 -0500 Subject: [PATCH 11/21] formatting --- docs/includes/usage-examples/FindOneTest.php | 4 +--- docs/includes/usage-examples/UpdateOneTest.php | 12 +++++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/docs/includes/usage-examples/FindOneTest.php b/docs/includes/usage-examples/FindOneTest.php index ee36f6fc5..4bfa93f10 100644 --- a/docs/includes/usage-examples/FindOneTest.php +++ b/docs/includes/usage-examples/FindOneTest.php @@ -8,8 +8,6 @@ use Illuminate\Support\Facades\DB; use MongoDB\Laravel\Tests\TestCase; -use function print_r; - class FindOneTest extends TestCase { /** @@ -34,7 +32,7 @@ public function testFindOne(): void // end-eloquent-find-one $this->assertInstanceOf(Movie::class, $movie); - + // begin-qb-find-one $movie = DB::table('movies') ->where('directors', 'Rob Reiner') diff --git a/docs/includes/usage-examples/UpdateOneTest.php b/docs/includes/usage-examples/UpdateOneTest.php index 6b4f417b1..53c1247b9 100644 --- a/docs/includes/usage-examples/UpdateOneTest.php +++ b/docs/includes/usage-examples/UpdateOneTest.php @@ -49,12 +49,14 @@ public function testUpdateOne(): void $updates = DB::table('movies') ->updateOne( ['title' => 'Carol'], - ['$set' => [ - 'imdb' => [ - 'rating' => 7.3, - 'votes' => 142000, + [ + '$set' => [ + 'imdb' => [ + 'rating' => 7.3, + 'votes' => 142000, + ], ], - ]] + ], ); echo 'Updated documents: ' . $updates; From e558e609133375a94468cb3ffa9158fde20331d1 Mon Sep 17 00:00:00 2001 From: rustagir Date: Fri, 31 Jan 2025 09:23:53 -0500 Subject: [PATCH 12/21] formatting --- docs/includes/usage-examples/FindOneTest.php | 1 + .../includes/usage-examples/InsertOneTest.php | 1 + .../includes/usage-examples/UpdateOneTest.php | 21 +--- docs/usage-examples/findOne.txt | 11 +- docs/usage-examples/updateOne.txt | 106 +++++------------- 5 files changed, 36 insertions(+), 104 deletions(-) diff --git a/docs/includes/usage-examples/FindOneTest.php b/docs/includes/usage-examples/FindOneTest.php index 4bfa93f10..4d7046571 100644 --- a/docs/includes/usage-examples/FindOneTest.php +++ b/docs/includes/usage-examples/FindOneTest.php @@ -43,5 +43,6 @@ public function testFindOne(): void // end-qb-find-one $this->assertSame($movie['title'], 'The Shawshank Redemption'); + $this->expectOutputString('{"_id":"679cdb4834e26dc5370de462","title":"The Shawshank Redemption","directors":["Frank Darabont","Rob Reiner"]}The Shawshank Redemption'); } } diff --git a/docs/includes/usage-examples/InsertOneTest.php b/docs/includes/usage-examples/InsertOneTest.php index 36517e888..0310c67dd 100644 --- a/docs/includes/usage-examples/InsertOneTest.php +++ b/docs/includes/usage-examples/InsertOneTest.php @@ -43,5 +43,6 @@ public function testInsertOne(): void $this->assertInstanceOf(Movie::class, $movie); $this->assertSame($movie->title, 'Marriage Story'); + $this->expectOutputString('{"title":"Marriage Story","year":2019,"runtime":136,"updated_at":"2025-01-31T14:16:40.834000Z","created_at":"2025-01-31T14:16:40.834000Z","_id":"679cdb488f9fa3d481091a42"}Insert operation success: yes'); } } diff --git a/docs/includes/usage-examples/UpdateOneTest.php b/docs/includes/usage-examples/UpdateOneTest.php index 53c1247b9..2ed356d5a 100644 --- a/docs/includes/usage-examples/UpdateOneTest.php +++ b/docs/includes/usage-examples/UpdateOneTest.php @@ -5,7 +5,6 @@ namespace App\Http\Controllers; use App\Models\Movie; -use Illuminate\Support\Facades\DB; use MongoDB\Laravel\Tests\TestCase; class UpdateOneTest extends TestCase @@ -44,24 +43,6 @@ public function testUpdateOne(): void // end-eloquent-update-one $this->assertTrue($updates); - - // begin-qb-update-one - $updates = DB::table('movies') - ->updateOne( - ['title' => 'Carol'], - [ - '$set' => [ - 'imdb' => [ - 'rating' => 7.3, - 'votes' => 142000, - ], - ], - ], - ); - - echo 'Updated documents: ' . $updates; - // end-qb-update-one - - $this->expectOutputString('Updated documents: 1Updated documents: 0'); + $this->expectOutputString('Updated documents: 1'); } } diff --git a/docs/usage-examples/findOne.txt b/docs/usage-examples/findOne.txt index 8995f02d4..d5df8aae1 100644 --- a/docs/usage-examples/findOne.txt +++ b/docs/usage-examples/findOne.txt @@ -89,7 +89,7 @@ each corresponding query syntax: method from the ``DB`` facade - Retrieves a document from the ``movies`` collection that matches a query filter - - Prints the retrieved document + - Prints the ``title`` field of the retrieved document The example calls the following query builder methods: @@ -110,13 +110,6 @@ each corresponding query syntax: :language: console :visible: false - // Result is truncated - - { - "_id": ..., - "title": "This Is Spinal Tap", - "directors": [ "Rob Reiner" ], - ... - } + This Is Spinal Tap .. include:: /includes/usage-examples/fact-edit-laravel-app.rst diff --git a/docs/usage-examples/updateOne.txt b/docs/usage-examples/updateOne.txt index 9470b4a5d..4600c0498 100644 --- a/docs/usage-examples/updateOne.txt +++ b/docs/usage-examples/updateOne.txt @@ -32,81 +32,37 @@ by passing your intended document changes to the ``update()`` method. Example ------- -Select from the following :guilabel:`Eloquent` and :guilabel:`Query -Builder` tabs to view usage examples for the same operation that use -each corresponding query syntax: - -.. tabs:: - - .. tab:: Eloquent - :tabid: eloquent-model-count - - This example performs the following actions: - - - Uses the ``Movie`` Eloquent model to represent the ``movies`` - collection in the ``sample_mflix`` database - - Updates a document from the ``movies`` collection that matches - the query filter - - Prints the number of updated documents - - The example calls the following methods on the ``Movie`` model: - - - ``where()``: Matches documents in which the value of the - ``title`` field is ``"Carol"`` - - ``orderBy()``: Sorts matched documents by their ascending ``_id`` values - - ``first()``: Retrieves only the first matching document. - - ``update()``: Updates the value of the ``imdb.rating`` nested - field to from ``6.9`` to ``7.3`` and the value of the - ``imdb.votes`` nested field from ``493`` to ``142000`` - - .. io-code-block:: - :copyable: true - - .. input:: ../includes/usage-examples/UpdateOneTest.php - :start-after: begin-eloquent-update-one - :end-before: end-eloquent-update-one - :language: php - :dedent: - - .. output:: - :language: console - :visible: false +This example performs the following actions: - Updated documents: 1 - - .. tab:: Query Builder - :tabid: query-builder-count - - This example performs the following actions: - - - Accesses the ``movies`` collection by calling the ``table()`` - method from the ``DB`` facade - - Updates a document from the ``movies`` collection that matches - the query filter - - Prints the number of updated documents - - The example calls the following query builder methods: - - - ``where()``: Matches documents in which the value of the - ``title`` field is ``"Carol"`` - - ``orderBy()``: Sorts matched documents by their ascending ``_id`` values - - ``first()``: Retrieves only the first matching document. - - ``update()``: Updates the value of the ``imdb.rating`` nested - field to from ``6.9`` to ``7.3`` and the value of the - ``imdb.votes`` nested field from ``493`` to ``142000`` - - .. io-code-block:: - - .. input:: ../includes/usage-examples/UpdateOneTest.php - :start-after: begin-qb-update-one - :end-before: end-qb-update-one - :language: php - :dedent: - - .. output:: - :language: console - :visible: false - - Updated documents: 1 +- Uses the ``Movie`` Eloquent model to represent the ``movies`` + collection in the ``sample_mflix`` database +- Updates a document from the ``movies`` collection that matches + the query filter +- Prints the number of updated documents + +The example calls the following methods on the ``Movie`` model: + +- ``where()``: Matches documents in which the value of the + ``title`` field is ``"Carol"`` +- ``orderBy()``: Sorts matched documents by their ascending ``_id`` values +- ``first()``: Retrieves only the first matching document. +- ``update()``: Updates the value of the ``imdb.rating`` nested + field to from ``6.9`` to ``7.3`` and the value of the + ``imdb.votes`` nested field from ``493`` to ``142000`` + +.. io-code-block:: + :copyable: true + + .. input:: ../includes/usage-examples/UpdateOneTest.php + :start-after: begin-eloquent-update-one + :end-before: end-eloquent-update-one + :language: php + :dedent: + + .. output:: + :language: console + :visible: false + + Updated documents: 1 .. include:: /includes/usage-examples/fact-edit-laravel-app.rst From b5a25b6c2a16c5a1f0ad66ade50efbb1a8b3ca10 Mon Sep 17 00:00:00 2001 From: rustagir Date: Fri, 31 Jan 2025 09:30:02 -0500 Subject: [PATCH 13/21] formatting --- docs/includes/usage-examples/FindOneTest.php | 3 +-- docs/usage-examples/insertOne.txt | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/docs/includes/usage-examples/FindOneTest.php b/docs/includes/usage-examples/FindOneTest.php index 4d7046571..f5871db5d 100644 --- a/docs/includes/usage-examples/FindOneTest.php +++ b/docs/includes/usage-examples/FindOneTest.php @@ -31,8 +31,6 @@ public function testFindOne(): void echo $movie->toJson(); // end-eloquent-find-one - $this->assertInstanceOf(Movie::class, $movie); - // begin-qb-find-one $movie = DB::table('movies') ->where('directors', 'Rob Reiner') @@ -42,6 +40,7 @@ public function testFindOne(): void echo $movie['title']; // end-qb-find-one + $this->assertInstanceOf(Movie::class, $movie); $this->assertSame($movie['title'], 'The Shawshank Redemption'); $this->expectOutputString('{"_id":"679cdb4834e26dc5370de462","title":"The Shawshank Redemption","directors":["Frank Darabont","Rob Reiner"]}The Shawshank Redemption'); } diff --git a/docs/usage-examples/insertOne.txt b/docs/usage-examples/insertOne.txt index 5bd059840..369a33895 100644 --- a/docs/usage-examples/insertOne.txt +++ b/docs/usage-examples/insertOne.txt @@ -86,7 +86,7 @@ each corresponding query syntax: method from the ``DB`` facade - Inserts a document into the ``movies`` collection - The example calls the ``create()`` method to insert a document + The example calls the ``insert()`` method to insert a document that contains the following fields and values: - ``title`` value of ``"Marriage Story"`` From cb4abe3bf682372ec21ec8b5f91337436adb9f95 Mon Sep 17 00:00:00 2001 From: rustagir Date: Fri, 31 Jan 2025 09:36:16 -0500 Subject: [PATCH 14/21] fix tests --- docs/includes/usage-examples/FindOneTest.php | 24 +++++++++++++++---- .../includes/usage-examples/InsertOneTest.php | 20 ++++++++++++---- 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/docs/includes/usage-examples/FindOneTest.php b/docs/includes/usage-examples/FindOneTest.php index f5871db5d..d641556d2 100644 --- a/docs/includes/usage-examples/FindOneTest.php +++ b/docs/includes/usage-examples/FindOneTest.php @@ -14,7 +14,7 @@ class FindOneTest extends TestCase * @runInSeparateProcess * @preserveGlobalState disabled */ - public function testFindOne(): void + public function testEloquentFindOne(): void { require_once __DIR__ . '/Movie.php'; @@ -25,12 +25,29 @@ public function testFindOne(): void // begin-eloquent-find-one $movie = Movie::where('directors', 'Rob Reiner') - ->orderBy('_id') + ->orderBy('id') ->first(); echo $movie->toJson(); // end-eloquent-find-one + $this->assertInstanceOf(Movie::class, $movie); + $this->expectOutputRegex('/^{"title":"The Shawshank Redemption","directors":\["Frank Darabont","Rob Reiner"\],"id":"[a-z0-9]{24}"}$/'); + } + + /** + * @runInSeparateProcess + * @preserveGlobalState disabled + */ + public function testQBFindOne(): void + { + require_once __DIR__ . '/Movie.php'; + + Movie::truncate(); + Movie::insert([ + ['title' => 'The Shawshank Redemption', 'directors' => ['Frank Darabont', 'Rob Reiner']], + ]); + // begin-qb-find-one $movie = DB::table('movies') ->where('directors', 'Rob Reiner') @@ -40,8 +57,7 @@ public function testFindOne(): void echo $movie['title']; // end-qb-find-one - $this->assertInstanceOf(Movie::class, $movie); $this->assertSame($movie['title'], 'The Shawshank Redemption'); - $this->expectOutputString('{"_id":"679cdb4834e26dc5370de462","title":"The Shawshank Redemption","directors":["Frank Darabont","Rob Reiner"]}The Shawshank Redemption'); + $this->expectOutputString('The Shawshank Redemption'); } } diff --git a/docs/includes/usage-examples/InsertOneTest.php b/docs/includes/usage-examples/InsertOneTest.php index 0310c67dd..4b8a8bdb7 100644 --- a/docs/includes/usage-examples/InsertOneTest.php +++ b/docs/includes/usage-examples/InsertOneTest.php @@ -14,7 +14,7 @@ class InsertOneTest extends TestCase * @runInSeparateProcess * @preserveGlobalState disabled */ - public function testInsertOne(): void + public function testEloquentInsertOne(): void { require_once __DIR__ . '/Movie.php'; @@ -30,6 +30,20 @@ public function testInsertOne(): void echo $movie->toJson(); // end-eloquent-insert-one + $this->assertInstanceOf(Movie::class, $movie); + $this->assertSame($movie->title, 'Marriage Story'); + } + + /** + * @runInSeparateProcess + * @preserveGlobalState disabled + */ + public function testQBInsertOne(): void + { + require_once __DIR__ . '/Movie.php'; + + Movie::truncate(); + // begin-qb-insert-one $success = DB::table('movies') ->insert([ @@ -41,8 +55,6 @@ public function testInsertOne(): void echo 'Insert operation success: ' . ($success ? 'yes' : 'no'); // end-qb-insert-one - $this->assertInstanceOf(Movie::class, $movie); - $this->assertSame($movie->title, 'Marriage Story'); - $this->expectOutputString('{"title":"Marriage Story","year":2019,"runtime":136,"updated_at":"2025-01-31T14:16:40.834000Z","created_at":"2025-01-31T14:16:40.834000Z","_id":"679cdb488f9fa3d481091a42"}Insert operation success: yes'); + $this->expectOutputString('Insert operation success: yes'); } } From 64fbd31a5269063ddb5b766d1420819910df678e Mon Sep 17 00:00:00 2001 From: rustagir Date: Fri, 31 Jan 2025 09:45:21 -0500 Subject: [PATCH 15/21] fix tests --- docs/includes/usage-examples/FindOneTest.php | 2 +- docs/includes/usage-examples/InsertOneTest.php | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/includes/usage-examples/FindOneTest.php b/docs/includes/usage-examples/FindOneTest.php index d641556d2..c5304d378 100644 --- a/docs/includes/usage-examples/FindOneTest.php +++ b/docs/includes/usage-examples/FindOneTest.php @@ -32,7 +32,7 @@ public function testEloquentFindOne(): void // end-eloquent-find-one $this->assertInstanceOf(Movie::class, $movie); - $this->expectOutputRegex('/^{"title":"The Shawshank Redemption","directors":\["Frank Darabont","Rob Reiner"\],"id":"[a-z0-9]{24}"}$/'); + $this->expectOutputRegex('/^{"_id":"[a-z0-9]{24}","title":"The Shawshank Redemption","directors":\["Frank Darabont","Rob Reiner"\]}$/'); } /** diff --git a/docs/includes/usage-examples/InsertOneTest.php b/docs/includes/usage-examples/InsertOneTest.php index 4b8a8bdb7..821029499 100644 --- a/docs/includes/usage-examples/InsertOneTest.php +++ b/docs/includes/usage-examples/InsertOneTest.php @@ -32,6 +32,7 @@ public function testEloquentInsertOne(): void $this->assertInstanceOf(Movie::class, $movie); $this->assertSame($movie->title, 'Marriage Story'); + $this->expectOutputRegex('/^{"title":"Marriage Story","year":2019,"runtime":136,"updated_at":".{27}","created_at":".{27}","_id":"[a-z0-9]{24}"}$/'); } /** From 33e2cce7e558f5073af6317bbca6cc8396051268 Mon Sep 17 00:00:00 2001 From: rustagir Date: Fri, 31 Jan 2025 10:06:31 -0500 Subject: [PATCH 16/21] small text changes --- docs/usage-examples/find.txt | 20 +++++--------------- docs/usage-examples/insertOne.txt | 2 ++ docs/usage-examples/updateOne.txt | 11 ++++++----- 3 files changed, 13 insertions(+), 20 deletions(-) diff --git a/docs/usage-examples/find.txt b/docs/usage-examples/find.txt index bb9892947..187676392 100644 --- a/docs/usage-examples/find.txt +++ b/docs/usage-examples/find.txt @@ -130,20 +130,10 @@ each corresponding query syntax: // Results are truncated - [ - { - "_id": ..., - "runtime": 1256, - "title": "Centennial", - ..., - }, - { - "_id": ..., - "runtime": 1140, - "title": "Baseball", - ..., - }, - ... - ] + Illuminate\Support\Collection Object ( [items:protected] => + Array ( [0] => Array ( [_id] => ... [runtime] => 1256 + [title] => Centennial [1] => Array + ( [_id] => ... [runtime] => 1140 + [title] => Baseball ) ... .. include:: /includes/usage-examples/fact-edit-laravel-app.rst diff --git a/docs/usage-examples/insertOne.txt b/docs/usage-examples/insertOne.txt index 369a33895..1a246ab72 100644 --- a/docs/usage-examples/insertOne.txt +++ b/docs/usage-examples/insertOne.txt @@ -47,6 +47,7 @@ each corresponding query syntax: - Uses the ``Movie`` Eloquent model to represent the ``movies`` collection in the ``sample_mflix`` database - Inserts a document into the ``movies`` collection + - Prints the newly inserted document The example calls the ``create()`` method to insert a document that contains the following fields and values: @@ -85,6 +86,7 @@ each corresponding query syntax: - Accesses the ``movies`` collection by calling the ``table()`` method from the ``DB`` facade - Inserts a document into the ``movies`` collection + - Prints whether the insert operation succeeds The example calls the ``insert()`` method to insert a document that contains the following fields and values: diff --git a/docs/usage-examples/updateOne.txt b/docs/usage-examples/updateOne.txt index 4600c0498..2b0674c4e 100644 --- a/docs/usage-examples/updateOne.txt +++ b/docs/usage-examples/updateOne.txt @@ -17,12 +17,13 @@ Update a Document :depth: 1 :class: singlecol -You can update a document in a collection by retrieving a single document and calling -the ``update()`` method on an Eloquent model or a query builder. +You can update a document in a collection by retrieving a single +document and calling the ``update()`` method on an Eloquent model. -Pass a query filter to the ``where()`` method, sort the matching documents, and call the -``first()`` method to retrieve only the first document. Then, update this matching document -by passing your intended document changes to the ``update()`` method. +Pass a query filter to the ``where()`` method, sort the matching +documents, and call the ``first()`` method to retrieve only the first +document. Then, update this matching document by passing your intended +document changes to the ``update()`` method. .. tip:: From c5dbb4c7c9a1f3ccf2577a26f2cceebb0b055365 Mon Sep 17 00:00:00 2001 From: rustagir Date: Fri, 31 Jan 2025 10:10:52 -0500 Subject: [PATCH 17/21] fix error --- docs/query-builder.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/query-builder.txt b/docs/query-builder.txt index 649cdde34..990c1005c 100644 --- a/docs/query-builder.txt +++ b/docs/query-builder.txt @@ -631,7 +631,7 @@ a query: :end-before: end options The query builder accepts the same options that you can set for -the :phpmethod:`find() ` method in the +the :phpmethod:`MongoDB\Collection::find()` method in the {+php-library+}. Some of the options to modify query results, such as ``skip``, ``sort``, and ``limit``, are settable directly as query builder methods and are described in the From 97f5b23a488ada02830d9013a48fe331a3f515dd Mon Sep 17 00:00:00 2001 From: rustagir Date: Fri, 31 Jan 2025 14:50:00 -0500 Subject: [PATCH 18/21] JS PR fixes 1 --- docs/usage-examples/insertMany.txt | 4 ++-- docs/usage-examples/updateOne.txt | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/usage-examples/insertMany.txt b/docs/usage-examples/insertMany.txt index 9d3a16b3e..48acfe17e 100644 --- a/docs/usage-examples/insertMany.txt +++ b/docs/usage-examples/insertMany.txt @@ -49,7 +49,7 @@ each corresponding query syntax: - Inserts documents into the ``movies`` collection - Prints whether the insert operation succeeds - The example calls the ``insert()`` method to insert documents that model + The example calls the ``insert()`` method to insert documents that represent movies released in ``2023``. If the insert operation is successful, it returns a value of ``1``. If the operation fails, it throws an exception. @@ -79,7 +79,7 @@ each corresponding query syntax: - Inserts documents into the ``movies`` collection - Prints whether the insert operation succeeds - The example calls the ``insert()`` method to insert documents that model + The example calls the ``insert()`` method to insert documents that represent movies released in ``2023``. If the insert operation is successful, it returns a value of ``1``. If the operation fails, it throws an exception. diff --git a/docs/usage-examples/updateOne.txt b/docs/usage-examples/updateOne.txt index 2b0674c4e..785ba3b09 100644 --- a/docs/usage-examples/updateOne.txt +++ b/docs/usage-examples/updateOne.txt @@ -46,7 +46,7 @@ The example calls the following methods on the ``Movie`` model: - ``where()``: Matches documents in which the value of the ``title`` field is ``"Carol"`` - ``orderBy()``: Sorts matched documents by their ascending ``_id`` values -- ``first()``: Retrieves only the first matching document. +- ``first()``: Retrieves only the first matching document - ``update()``: Updates the value of the ``imdb.rating`` nested field to from ``6.9`` to ``7.3`` and the value of the ``imdb.votes`` nested field from ``493`` to ``142000`` From b823e4740e0993d880c38b9e09fecd2a9f6fc87e Mon Sep 17 00:00:00 2001 From: rustagir Date: Fri, 31 Jan 2025 16:29:13 -0500 Subject: [PATCH 19/21] add extra tests for each type of query --- docs/includes/usage-examples/CountTest.php | 2 ++ .../usage-examples/DeleteManyTest.php | 15 +++++++++++++- .../includes/usage-examples/DeleteOneTest.php | 12 ++++++++++- docs/includes/usage-examples/FindManyTest.php | 2 ++ .../usage-examples/InsertManyTest.php | 2 ++ .../usage-examples/UpdateManyTest.php | 20 ++++++++++++++++++- 6 files changed, 50 insertions(+), 3 deletions(-) diff --git a/docs/includes/usage-examples/CountTest.php b/docs/includes/usage-examples/CountTest.php index b3cbc01e1..41acec6bd 100644 --- a/docs/includes/usage-examples/CountTest.php +++ b/docs/includes/usage-examples/CountTest.php @@ -36,6 +36,8 @@ public function testCount(): void echo 'Number of documents: ' . $count; // end-eloquent-count + + $this->assertEquals(2, $count); // begin-qb-count $count = DB::table('movies') diff --git a/docs/includes/usage-examples/DeleteManyTest.php b/docs/includes/usage-examples/DeleteManyTest.php index 638423776..8948c06fb 100644 --- a/docs/includes/usage-examples/DeleteManyTest.php +++ b/docs/includes/usage-examples/DeleteManyTest.php @@ -38,7 +38,17 @@ public function testDeleteMany(): void // end-eloquent-delete-many $this->assertEquals(2, $deleted); - $this->expectOutputString('Deleted documents: 2Deleted documents: 0'); + + Movie::insert([ + [ + 'title' => 'Train Pulling into a Station', + 'year' => 1896, + ], + [ + 'title' => 'The Ball Game', + 'year' => 1898, + ], + ]); // begin-qb-delete-many $deleted = DB::table('movies') @@ -47,5 +57,8 @@ public function testDeleteMany(): void echo 'Deleted documents: ' . $deleted; // end-qb-delete-many + + $this->assertEquals(2, $deleted); + $this->expectOutputString('Deleted documents: 2Deleted documents: 2'); } } diff --git a/docs/includes/usage-examples/DeleteOneTest.php b/docs/includes/usage-examples/DeleteOneTest.php index 71fecf033..caf17ea70 100644 --- a/docs/includes/usage-examples/DeleteOneTest.php +++ b/docs/includes/usage-examples/DeleteOneTest.php @@ -36,7 +36,13 @@ public function testDeleteOne(): void // end-eloquent-delete-one $this->assertEquals(1, $deleted); - $this->expectOutputString('Deleted documents: 1Deleted documents: 0'); + + Movie::insert([ + [ + 'title' => 'Quiz Show', + 'runtime' => 133, + ], + ]); // begin-qb-delete-one $deleted = DB::table('movies') @@ -47,5 +53,9 @@ public function testDeleteOne(): void echo 'Deleted documents: ' . $deleted; // end-qb-delete-one + + $this->assertEquals(1, $deleted); + + $this->expectOutputString('Deleted documents: 1Deleted documents: 1'); } } diff --git a/docs/includes/usage-examples/FindManyTest.php b/docs/includes/usage-examples/FindManyTest.php index 6293e8a8a..e136c65d7 100644 --- a/docs/includes/usage-examples/FindManyTest.php +++ b/docs/includes/usage-examples/FindManyTest.php @@ -40,6 +40,8 @@ public function testFindMany(): void ->get(); // end-eloquent-find + $this->assertEquals(2, $movies->count()); + // begin-qb-find $movies = DB::table('movies') ->where('runtime', '>', 900) diff --git a/docs/includes/usage-examples/InsertManyTest.php b/docs/includes/usage-examples/InsertManyTest.php index 85ba50f36..79e00971f 100644 --- a/docs/includes/usage-examples/InsertManyTest.php +++ b/docs/includes/usage-examples/InsertManyTest.php @@ -41,6 +41,8 @@ public function testInsertMany(): void echo 'Insert operation success: ' . ($success ? 'yes' : 'no'); // end-eloquent-insert-many + $this->assertTrue($success); + // begin-qb-insert-many $success = DB::table('movies') ->insert([ diff --git a/docs/includes/usage-examples/UpdateManyTest.php b/docs/includes/usage-examples/UpdateManyTest.php index 897afe706..9d4a11ac8 100644 --- a/docs/includes/usage-examples/UpdateManyTest.php +++ b/docs/includes/usage-examples/UpdateManyTest.php @@ -45,6 +45,23 @@ public function testUpdateMany(): void $this->assertEquals(2, $updates); + Movie::insert([ + [ + 'title' => 'ABCD', + 'imdb' => [ + 'rating' => 9.5, + 'votes' => 1, + ], + ], + [ + 'title' => 'Testing', + 'imdb' => [ + 'rating' => 9.3, + 'votes' => 1, + ], + ], + ]); + // begin-qb-update-many $updates = DB::table('movies') ->where('imdb.rating', '>', 9.0) @@ -53,6 +70,7 @@ public function testUpdateMany(): void echo 'Updated documents: ' . $updates; // end-qb-update-many - $this->expectOutputString('Updated documents: 2Updated documents: 0'); + $this->assertEquals(2, $updates); + $this->expectOutputString('Updated documents: 2Updated documents: 2'); } } From e6136c7c7e3dfe63de7c24e05b71c31ed10f16ec Mon Sep 17 00:00:00 2001 From: rustagir Date: Fri, 31 Jan 2025 16:30:59 -0500 Subject: [PATCH 20/21] formatting --- docs/includes/usage-examples/CountTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/includes/usage-examples/CountTest.php b/docs/includes/usage-examples/CountTest.php index 41acec6bd..5e7e34c62 100644 --- a/docs/includes/usage-examples/CountTest.php +++ b/docs/includes/usage-examples/CountTest.php @@ -36,7 +36,7 @@ public function testCount(): void echo 'Number of documents: ' . $count; // end-eloquent-count - + $this->assertEquals(2, $count); // begin-qb-count From 398d4afb532fe9d9d5568e8bb1df79d928589649 Mon Sep 17 00:00:00 2001 From: rustagir Date: Thu, 6 Feb 2025 14:38:18 -0500 Subject: [PATCH 21/21] remove sort from deleteOne --- docs/includes/usage-examples/DeleteOneTest.php | 3 --- docs/usage-examples/deleteOne.txt | 2 -- 2 files changed, 5 deletions(-) diff --git a/docs/includes/usage-examples/DeleteOneTest.php b/docs/includes/usage-examples/DeleteOneTest.php index caf17ea70..9038618f8 100644 --- a/docs/includes/usage-examples/DeleteOneTest.php +++ b/docs/includes/usage-examples/DeleteOneTest.php @@ -28,7 +28,6 @@ public function testDeleteOne(): void // begin-eloquent-delete-one $deleted = Movie::where('title', 'Quiz Show') - ->orderBy('_id') ->limit(1) ->delete(); @@ -47,7 +46,6 @@ public function testDeleteOne(): void // begin-qb-delete-one $deleted = DB::table('movies') ->where('title', 'Quiz Show') - ->orderBy('_id') ->limit(1) ->delete(); @@ -55,7 +53,6 @@ public function testDeleteOne(): void // end-qb-delete-one $this->assertEquals(1, $deleted); - $this->expectOutputString('Deleted documents: 1Deleted documents: 1'); } } diff --git a/docs/usage-examples/deleteOne.txt b/docs/usage-examples/deleteOne.txt index 940564bd5..8a88c0241 100644 --- a/docs/usage-examples/deleteOne.txt +++ b/docs/usage-examples/deleteOne.txt @@ -56,7 +56,6 @@ each corresponding query syntax: - ``where()``: Matches documents in which the value of the ``title`` field is ``"Quiz Show"`` - - ``orderBy()``: Sorts matched documents by their ascending ``_id`` values - ``limit()``: Retrieves only the first matching document - ``delete()``: Deletes the retrieved document @@ -90,7 +89,6 @@ each corresponding query syntax: - ``where()``: Matches documents in which the value of the ``title`` field is ``"Quiz Show"`` - - ``orderBy()``: Sorts matched documents by their ascending ``_id`` values - ``limit()``: Retrieves only the first matching document - ``delete()``: Deletes the retrieved document