From 2a01a1f25fc5f57286edfa3e47d98b614b897607 Mon Sep 17 00:00:00 2001 From: norareidy Date: Wed, 13 Mar 2024 11:30:50 -0400 Subject: [PATCH 01/26] DOCSP-35974: Update one usage example --- docs/usage-examples/updateOne.txt | 98 +++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 docs/usage-examples/updateOne.txt diff --git a/docs/usage-examples/updateOne.txt b/docs/usage-examples/updateOne.txt new file mode 100644 index 000000000..6319ee698 --- /dev/null +++ b/docs/usage-examples/updateOne.txt @@ -0,0 +1,98 @@ +.. _laravel-update-one-usage: + +================= +Update a Document +================= + +You can update a document in a collection by calling the ``where()``, ``first()``, +and ``update()`` methods on an Eloquent model or a query builder. + +Pass a query filter to the ``where()`` method and call the ``first()`` method to match +only one document. Then, pass the document changes to the ``update()`` method to update +one document that matches the filter. + +To learn more about updating data with {+odm-short+}, see the `Updates +`__ section of the Laravel documentation. + +Example +------- + +This example updates a document that matches a query filter from the ``movies`` +collection in the ``sample_mflix`` database. The example uses the ``Movie`` Eloquent model +to represent the ``movies`` collection. + +This example uses a query filter that matches documents in which the value of the +``title`` field is ``'Carol'``. Then, the ``first()`` method MongoDB retrieves the first document that +matches the query filter, according to the sort order specified by the ``orderBy()`` method. The +``update()`` method updates the value of the ``metacritic`` field from ``98`` to ``94``. + +Select the :guilabel:`Controller File Code` tab and paste the code example into the +``MovieController.php`` file. This tab contains the find operation code. + +Then, select the :guilabel:`View File Code` tab and paste the code example into +``browse_movies.blade.php``. This tab contains the view code to generate the expected output, +which you can see by visiting http://127.0.0.1:8000/browse_movies. + +.. important:: + + Before running the update operation, you must add the following statement to the + ``Movie`` class in your ``Movie.php`` file: + + .. code-block:: php + + protected $fillable = array('metacritic'); + + The ``$fillable`` property specifies which document fields are mass-assignable. To learn + more about ``$fillable``, see the `Mass Assignment `__ + section of the Laravel documentation. + + +.. tabs:: + + .. tab:: Controller File Code + :tabid: find-one-controller + + .. code-block:: php + + class MovieController + { + public function show() + { + $update = Movie::where('title', 'Carol') + ->orderBy('_id') + ->first() + ->update(['metacritic' => 94]); + + return view('browse_movies', [ + 'updates' => $update + ]); + } + } + + .. tab:: View File Code + :tabid: find-one-view + + .. io-code-block:: + :copyable: true + + .. input:: + :language: php + + + + + Browse Movies + + +

Movies

+

+ Updated documents: {{ $updates }}
+

+ + + + .. output:: + :language: console + :visible: false + + Updated documents: 1 \ No newline at end of file From 5d5bc52b74a532f8db2d3d19e2d99c127a60e86b Mon Sep 17 00:00:00 2001 From: norareidy Date: Wed, 13 Mar 2024 13:29:42 -0400 Subject: [PATCH 02/26] fixes --- docs/usage-examples/updateOne.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/docs/usage-examples/updateOne.txt b/docs/usage-examples/updateOne.txt index 6319ee698..ca5a1c2a4 100644 --- a/docs/usage-examples/updateOne.txt +++ b/docs/usage-examples/updateOne.txt @@ -46,7 +46,6 @@ which you can see by visiting http://127.0.0.1:8000/browse_movies. more about ``$fillable``, see the `Mass Assignment `__ section of the Laravel documentation. - .. tabs:: .. tab:: Controller File Code From de2fb197214767c4cbb71f9911d6737350f7c8e7 Mon Sep 17 00:00:00 2001 From: norareidy Date: Fri, 15 Mar 2024 14:25:22 -0400 Subject: [PATCH 03/26] other usage ex changes --- docs/usage-examples/updateOne.txt | 38 ++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/docs/usage-examples/updateOne.txt b/docs/usage-examples/updateOne.txt index ca5a1c2a4..7004106e9 100644 --- a/docs/usage-examples/updateOne.txt +++ b/docs/usage-examples/updateOne.txt @@ -4,8 +4,8 @@ Update a Document ================= -You can update a document in a collection by calling the ``where()``, ``first()``, -and ``update()`` methods on an Eloquent model or a query builder. +You can update a document in a collection by chaining the ``where()``, ``first()``, +and ``update()`` methods to an Eloquent model or a query builder. Pass a query filter to the ``where()`` method and call the ``first()`` method to match only one document. Then, pass the document changes to the ``update()`` method to update @@ -17,21 +17,21 @@ To learn more about updating data with {+odm-short+}, see the `Updates Example ------- -This example updates a document that matches a query filter from the ``movies`` +This usage example updates a document that matches a query filter from the ``movies`` collection in the ``sample_mflix`` database. The example uses the ``Movie`` Eloquent model to represent the ``movies`` collection. -This example uses a query filter that matches documents in which the value of the -``title`` field is ``'Carol'``. Then, the ``first()`` method MongoDB retrieves the first document that -matches the query filter, according to the sort order specified by the ``orderBy()`` method. The -``update()`` method updates the value of the ``metacritic`` field from ``98`` to ``94``. +This example performs the following actions: -Select the :guilabel:`Controller File Code` tab and paste the code example into the -``MovieController.php`` file. This tab contains the find operation code. +- Defines a query filter to match documents in which the value of the ``title`` field + is ``'Carol'`` +- Calls the ``first()`` method to retrieve the first document that matches the query filter, + according to the sort order specified by the ``orderBy()`` method +- Calls the ``update()`` method to update the value of the ``metacritic`` field from ``98`` + to ``94`` -Then, select the :guilabel:`View File Code` tab and paste the code example into -``browse_movies.blade.php``. This tab contains the view code to generate the expected output, -which you can see by visiting http://127.0.0.1:8000/browse_movies. +To see the update operation code, select the :guilabel:`Controller File Code` tab. To see +the HTML code that specifies a view, select the :guilabel:`View File Code` tab. .. important:: @@ -94,4 +94,16 @@ which you can see by visiting http://127.0.0.1:8000/browse_movies. :language: console :visible: false - Updated documents: 1 \ No newline at end of file + Updated documents: 1 + +To perform the update operation, start your Laravel application by running the following command: + +.. code-block:: bash + + php artisan serve + +Then, open the following URL in your web browser to view the expected output: + +.. code-block:: none + + http://127.0.0.1:8000/browse_movies \ No newline at end of file From 0f0479ce92d2804bdb07cde4990cdd773a555f68 Mon Sep 17 00:00:00 2001 From: norareidy Date: Tue, 19 Mar 2024 12:06:59 -0400 Subject: [PATCH 04/26] reworking the example --- docs/usage-examples/updateOne.txt | 123 ++++++++++++++---------------- 1 file changed, 56 insertions(+), 67 deletions(-) diff --git a/docs/usage-examples/updateOne.txt b/docs/usage-examples/updateOne.txt index 7004106e9..8a34e3341 100644 --- a/docs/usage-examples/updateOne.txt +++ b/docs/usage-examples/updateOne.txt @@ -25,85 +25,74 @@ This example performs the following actions: - Defines a query filter to match documents in which the value of the ``title`` field is ``'Carol'`` -- Calls the ``first()`` method to retrieve the first document that matches the query filter, - according to the sort order specified by the ``orderBy()`` method -- Calls the ``update()`` method to update the value of the ``metacritic`` field from ``98`` - to ``94`` - -To see the update operation code, select the :guilabel:`Controller File Code` tab. To see -the HTML code that specifies a view, select the :guilabel:`View File Code` tab. +- Calls the ``first()`` method to match only one document +- Calls the ``update()`` method to update the value of the ``imdb`` field .. important:: - Before running the update operation, you must add the following statement to the - ``Movie`` class in your ``Movie.php`` file: - - .. code-block:: php - - protected $fillable = array('metacritic'); - - The ``$fillable`` property specifies which document fields are mass-assignable. To learn - more about ``$fillable``, see the `Mass Assignment `__ - section of the Laravel documentation. - -.. tabs:: - - .. tab:: Controller File Code - :tabid: find-one-controller - - .. code-block:: php - - class MovieController - { - public function show() - { - $update = Movie::where('title', 'Carol') - ->orderBy('_id') - ->first() - ->update(['metacritic' => 94]); - - return view('browse_movies', [ - 'updates' => $update - ]); - } - } - - .. tab:: View File Code - :tabid: find-one-view + Before running the usage example, you must specify the changes to the ``imdb`` field in + the ``movie.json`` file, created in the :ref:`laravel-quick-start-write-data` step of + the Quick Start. Replace the contents of ``movie.json`` with the following data: - .. io-code-block:: - :copyable: true + .. code-block:: bash - .. input:: - :language: php - - - - - Browse Movies - - -

Movies

-

- Updated documents: {{ $updates }}
-

- - + { + "imdb": { + "rating": 7.3, + "votes": 142000 + } + } + +.. io-code-block:: + :copyable: true + + .. input:: + :language: php + + public function store(Request $request) + { + $movie = Movie::where('title', 'Carol') + ->first() + ->update(['imdb' => $request->imdb]); + $movie->save(); + } + + public function show() + { + return view('browse_movies', [ + 'movies' => Movie::where('title', 'Carol') + ->get() + ]); + } + + .. output:: + :language: console + :visible: false + + Title: Carol + Year: 2015 + Runtime: 118 + IMDB Rating: 7.3 + IMDB Votes: 142000 + Plot: Set in 1950s New York, a department-store clerk who dreams of a better life falls for an older, married woman. + +To perform the update operation, edit the ``store()`` and ``show()`` functions in your +``MovieController.php`` file to match the preceding code. Then, start your application +by running the following command: - .. output:: - :language: console - :visible: false +.. code-block:: bash - Updated documents: 1 + php artisan serve -To perform the update operation, start your Laravel application by running the following command: +Send the JSON payload to the endpoint as a ``POST`` request by running the following command: .. code-block:: bash - php artisan serve + curl -H "Content-Type: application/json" --data @movie.json http://localhost:8000/api/movies -Then, open the following URL in your web browser to view the expected output: +Open the following URL in your web browser to view the modified document: .. code-block:: none - http://127.0.0.1:8000/browse_movies \ No newline at end of file + http://127.0.0.1:8000/browse_movies + From 6edf281ebaa0f85d238fd7ca7382a2c23ac43d16 Mon Sep 17 00:00:00 2001 From: norareidy Date: Tue, 19 Mar 2024 13:46:10 -0400 Subject: [PATCH 05/26] add tip, spacing --- docs/usage-examples/updateOne.txt | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/docs/usage-examples/updateOne.txt b/docs/usage-examples/updateOne.txt index 8a34e3341..741bf5f2d 100644 --- a/docs/usage-examples/updateOne.txt +++ b/docs/usage-examples/updateOne.txt @@ -61,8 +61,8 @@ This example performs the following actions: { return view('browse_movies', [ 'movies' => Movie::where('title', 'Carol') - ->get() - ]); + ->get() + ]); } .. output:: @@ -74,7 +74,8 @@ This example performs the following actions: Runtime: 118 IMDB Rating: 7.3 IMDB Votes: 142000 - Plot: Set in 1950s New York, a department-store clerk who dreams of a better life falls for an older, married woman. + Plot: Set in 1950s New York, a department-store clerk who dreams of a better life falls + for an older, married woman. To perform the update operation, edit the ``store()`` and ``show()`` functions in your ``MovieController.php`` file to match the preceding code. Then, start your application @@ -96,3 +97,7 @@ Open the following URL in your web browser to view the modified document: http://127.0.0.1:8000/browse_movies +.. tip:: + + For more information on adding the usage example to your application, see the + :ref:`add-usage-examples` section of the Usage Example landing page. \ No newline at end of file From 8bcf1a7aefbb55aaba4af78e212f471840bed234 Mon Sep 17 00:00:00 2001 From: norareidy Date: Wed, 20 Mar 2024 11:31:10 -0400 Subject: [PATCH 06/26] restructuring --- docs/usage-examples/updateOne.txt | 74 +++++++++++-------------------- 1 file changed, 27 insertions(+), 47 deletions(-) diff --git a/docs/usage-examples/updateOne.txt b/docs/usage-examples/updateOne.txt index 741bf5f2d..b1d22b8c8 100644 --- a/docs/usage-examples/updateOne.txt +++ b/docs/usage-examples/updateOne.txt @@ -4,6 +4,19 @@ Update a Document ================= +.. facet:: + :name: genre + :values: reference + +.. meta:: + :keywords: update one, modify, code example + +.. contents:: On this page + :local: + :backlinks: none + :depth: 1 + :class: singlecol + You can update a document in a collection by chaining the ``where()``, ``first()``, and ``update()`` methods to an Eloquent model or a query builder. @@ -26,22 +39,8 @@ This example performs the following actions: - Defines a query filter to match documents in which the value of the ``title`` field is ``'Carol'`` - Calls the ``first()`` method to match only one document -- Calls the ``update()`` method to update the value of the ``imdb`` field - -.. important:: - - Before running the usage example, you must specify the changes to the ``imdb`` field in - the ``movie.json`` file, created in the :ref:`laravel-quick-start-write-data` step of - the Quick Start. Replace the contents of ``movie.json`` with the following data: - - .. code-block:: bash - - { - "imdb": { - "rating": 7.3, - "votes": 142000 - } - } +- Calls the ``update()`` method to update the value of the ``imdb.rating`` nested field to + ``7.3`` and the ``imdb.votes`` nested field to ``142000`` .. io-code-block:: :copyable: true @@ -49,21 +48,14 @@ This example performs the following actions: .. input:: :language: php - public function store(Request $request) - { - $movie = Movie::where('title', 'Carol') - ->first() - ->update(['imdb' => $request->imdb]); - $movie->save(); - } - - public function show() - { - return view('browse_movies', [ - 'movies' => Movie::where('title', 'Carol') - ->get() + $movie = Movie::where('title', 'Carol') + ->first() + ->update([ + "imdb" => [ + "rating" => 7.3, + "votes" => 142000 + ], ]); - } .. output:: :language: console @@ -77,27 +69,15 @@ This example performs the following actions: Plot: Set in 1950s New York, a department-store clerk who dreams of a better life falls for an older, married woman. -To perform the update operation, edit the ``store()`` and ``show()`` functions in your -``MovieController.php`` file to match the preceding code. Then, start your application +To view the result, run the operation in a controller endpoint. Then, start your application by running the following command: .. code-block:: bash php artisan serve -Send the JSON payload to the endpoint as a ``POST`` request by running the following command: - -.. code-block:: bash - - curl -H "Content-Type: application/json" --data @movie.json http://localhost:8000/api/movies - -Open the following URL in your web browser to view the modified document: - -.. code-block:: none - - http://127.0.0.1:8000/browse_movies - -.. tip:: +.. tip:: - For more information on adding the usage example to your application, see the - :ref:`add-usage-examples` section of the Usage Example landing page. \ No newline at end of file + You can add this usage example to the Laravel application created in the :ref:`laravel-quick-start` + and view the expected output. For instructions on running the update operation by editing your + {+quickstart-app-name+}, see the :ref:`Usage Example landing page `. \ No newline at end of file From a1238b0bb4c8f6001b18abf01949fc25319b153b Mon Sep 17 00:00:00 2001 From: norareidy Date: Wed, 20 Mar 2024 11:45:37 -0400 Subject: [PATCH 07/26] reword tip --- docs/usage-examples/updateOne.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/usage-examples/updateOne.txt b/docs/usage-examples/updateOne.txt index b1d22b8c8..74fd7bba8 100644 --- a/docs/usage-examples/updateOne.txt +++ b/docs/usage-examples/updateOne.txt @@ -79,5 +79,5 @@ by running the following command: .. tip:: You can add this usage example to the Laravel application created in the :ref:`laravel-quick-start` - and view the expected output. For instructions on running the update operation by editing your - {+quickstart-app-name+}, see the :ref:`Usage Example landing page `. \ No newline at end of file + and view the expected output. For instructions on editing your {+quickstart-app-name+} application + to run the usage example, see the :ref:`Usage Example landing page `. \ No newline at end of file From 30be915d269e34b5fc5196925724b0616b65c1f0 Mon Sep 17 00:00:00 2001 From: norareidy Date: Wed, 20 Mar 2024 13:51:51 -0400 Subject: [PATCH 08/26] fixes --- docs/usage-examples/updateOne.txt | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/docs/usage-examples/updateOne.txt b/docs/usage-examples/updateOne.txt index 74fd7bba8..7494061e2 100644 --- a/docs/usage-examples/updateOne.txt +++ b/docs/usage-examples/updateOne.txt @@ -69,15 +69,10 @@ This example performs the following actions: Plot: Set in 1950s New York, a department-store clerk who dreams of a better life falls for an older, married woman. -To view the result, run the operation in a controller endpoint. Then, start your application -by running the following command: - -.. code-block:: bash - - php artisan serve +To view the result, run the operation in a controller endpoint. .. tip:: You can add this usage example to the Laravel application created in the :ref:`laravel-quick-start` - and view the expected output. For instructions on editing your {+quickstart-app-name+} application + and view the expected output. For instructions on editing your ``{+quickstart-app-name+}`` application to run the usage example, see the :ref:`Usage Example landing page `. \ No newline at end of file From 3f9ef3d9f821e76aa73542dec4b842b4c4ba0ff4 Mon Sep 17 00:00:00 2001 From: norareidy Date: Wed, 20 Mar 2024 17:05:38 -0400 Subject: [PATCH 09/26] edits --- docs/usage-examples/updateOne.txt | 42 +++++++++++++++++-------------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/docs/usage-examples/updateOne.txt b/docs/usage-examples/updateOne.txt index 7494061e2..666c3b55b 100644 --- a/docs/usage-examples/updateOne.txt +++ b/docs/usage-examples/updateOne.txt @@ -17,30 +17,29 @@ Update a Document :depth: 1 :class: singlecol -You can update a document in a collection by chaining the ``where()``, ``first()``, -and ``update()`` methods to 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 or a query builder. -Pass a query filter to the ``where()`` method and call the ``first()`` method to match -only one document. Then, pass the document changes to the ``update()`` method to update -one document that matches the filter. - -To learn more about updating data with {+odm-short+}, see the `Updates -`__ section of the Laravel documentation. +Pass a query filter to the ``where()`` method, sort the matching documents, and call the +``first()`` method to match only one document. Then, pass the changes you want to make to +the document to the ``update()`` method to update one document that matches the filter. Example ------- -This usage example updates a document that matches a query filter from the ``movies`` -collection in the ``sample_mflix`` database. The example uses the ``Movie`` Eloquent model -to represent the ``movies`` collection. +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 a query filter. -This example performs the following actions: +The example calls the following methods on the ``Movie`` model: -- Defines a query filter to match documents in which the value of the ``title`` field - is ``'Carol'`` -- Calls the ``first()`` method to match only one document -- Calls the ``update()`` method to update the value of the ``imdb.rating`` nested field to - ``7.3`` and the ``imdb.votes`` nested field to ``142000`` +- ``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``. This method also updates the ``imdb.votes`` nested field from ``493`` to ``142000``. .. io-code-block:: :copyable: true @@ -49,6 +48,7 @@ This example performs the following actions: :language: php $movie = Movie::where('title', 'Carol') + ->orderBy('_id') ->first() ->update([ "imdb" => [ @@ -69,10 +69,14 @@ This example performs the following actions: Plot: Set in 1950s New York, a department-store clerk who dreams of a better life falls for an older, married woman. -To view the result, run the operation in a controller endpoint. +To view the result, run the operation in a controller endpoint. Then, query for the document that has +a ``'title'`` value of ``"Carol"`` and pass it to a view to see the updated document. .. tip:: You can add this usage example to the Laravel application created in the :ref:`laravel-quick-start` and view the expected output. For instructions on editing your ``{+quickstart-app-name+}`` application - to run the usage example, see the :ref:`Usage Example landing page `. \ No newline at end of file + to run the usage example, see the :ref:`Usage Example landing page `. + +To learn more about updating data with {+odm-short+}, see the `Updates +`__ section of the Laravel documentation. \ No newline at end of file From 82a4f2021545b12ae9811a7fe7941c9f0adeefb9 Mon Sep 17 00:00:00 2001 From: norareidy Date: Wed, 20 Mar 2024 17:10:21 -0400 Subject: [PATCH 10/26] reword --- docs/usage-examples/updateOne.txt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/usage-examples/updateOne.txt b/docs/usage-examples/updateOne.txt index 666c3b55b..038eae3f2 100644 --- a/docs/usage-examples/updateOne.txt +++ b/docs/usage-examples/updateOne.txt @@ -21,13 +21,13 @@ You can update a document in a collection by retrieving a single document and ca the ``update()`` method on an Eloquent model or a query builder. Pass a query filter to the ``where()`` method, sort the matching documents, and call the -``first()`` method to match only one document. Then, pass the changes you want to make to -the document to the ``update()`` method to update one document that matches the filter. +``first()`` method to match only one document. Then, update this matching document by passing +your intended document changes to the ``update()`` method. Example ------- -This usage example performs the following actions +This usage example performs the following actions: - Uses the ``Movie`` Eloquent model to represent the ``movies`` collection in the ``sample_mflix`` database. @@ -70,7 +70,7 @@ The example calls the following methods on the ``Movie`` model: for an older, married woman. To view the result, run the operation in a controller endpoint. Then, query for the document that has -a ``'title'`` value of ``"Carol"`` and pass it to a view to see the updated document. +a ``title`` value of ``'Carol'`` and pass it to a view to see the updated document. .. tip:: From 74db7ef574ee31a47983dbad10070d92f561c31d Mon Sep 17 00:00:00 2001 From: norareidy Date: Thu, 21 Mar 2024 13:37:19 -0400 Subject: [PATCH 11/26] add more running info --- docs/usage-examples/updateOne.txt | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/docs/usage-examples/updateOne.txt b/docs/usage-examples/updateOne.txt index 038eae3f2..23dce3ed7 100644 --- a/docs/usage-examples/updateOne.txt +++ b/docs/usage-examples/updateOne.txt @@ -61,16 +61,11 @@ The example calls the following methods on the ``Movie`` model: :language: console :visible: false - Title: Carol - Year: 2015 - Runtime: 118 - IMDB Rating: 7.3 - IMDB Votes: 142000 - Plot: Set in 1950s New York, a department-store clerk who dreams of a better life falls - for an older, married woman. - -To view the result, run the operation in a controller endpoint. Then, query for the document that has -a ``title`` value of ``'Carol'`` and pass it to a view to see the updated document. + 1 + +The expected output shows the number of modified documents. To view the output, add the operation +to a controller endpoint. Then, create a web route that calls the controller endpoint and returns +the result to a view. .. tip:: From c9e279cb744391177af85979fcf80cc2e3c2be78 Mon Sep 17 00:00:00 2001 From: norareidy Date: Thu, 21 Mar 2024 13:49:16 -0400 Subject: [PATCH 12/26] small change --- docs/usage-examples/updateOne.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/usage-examples/updateOne.txt b/docs/usage-examples/updateOne.txt index 23dce3ed7..b663ea11d 100644 --- a/docs/usage-examples/updateOne.txt +++ b/docs/usage-examples/updateOne.txt @@ -65,7 +65,7 @@ The example calls the following methods on the ``Movie`` model: The expected output shows the number of modified documents. To view the output, add the operation to a controller endpoint. Then, create a web route that calls the controller endpoint and returns -the result to a view. +the result to a web interface. .. tip:: From ae4bb21ab30dd22d9bc4f3ba2a5b7884de81e106 Mon Sep 17 00:00:00 2001 From: norareidy Date: Fri, 22 Mar 2024 13:58:55 -0400 Subject: [PATCH 13/26] edits --- docs/usage-examples/updateOne.txt | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/docs/usage-examples/updateOne.txt b/docs/usage-examples/updateOne.txt index b663ea11d..48fdfe02d 100644 --- a/docs/usage-examples/updateOne.txt +++ b/docs/usage-examples/updateOne.txt @@ -47,7 +47,7 @@ The example calls the following methods on the ``Movie`` model: .. input:: :language: php - $movie = Movie::where('title', 'Carol') + $updates = Movie::where('title', 'Carol') ->orderBy('_id') ->first() ->update([ @@ -56,22 +56,20 @@ The example calls the following methods on the ``Movie`` model: "votes" => 142000 ], ]); + + echo "Updated documents: {$updates}"; .. output:: :language: console :visible: false - 1 + Updated documents: 1 -The expected output shows the number of modified documents. To view the output, add the operation -to a controller endpoint. Then, create a web route that calls the controller endpoint and returns -the result to a web interface. +For instructions on editing your Laravel application to run the usage example, see the +:ref:`Usage Example landing page `. .. tip:: - You can add this usage example to the Laravel application created in the :ref:`laravel-quick-start` - and view the expected output. For instructions on editing your ``{+quickstart-app-name+}`` application - to run the usage example, see the :ref:`Usage Example landing page `. + To learn more about updating data with {+odm-short+}, see the `Updates + `__ section of the Laravel documentation. -To learn more about updating data with {+odm-short+}, see the `Updates -`__ section of the Laravel documentation. \ No newline at end of file From 5ceb6b38ff76888fc3790a272187239920c16139 Mon Sep 17 00:00:00 2001 From: norareidy Date: Fri, 22 Mar 2024 17:07:33 -0400 Subject: [PATCH 14/26] source constant --- docs/usage-examples/updateOne.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/usage-examples/updateOne.txt b/docs/usage-examples/updateOne.txt index 48fdfe02d..3c0cb648c 100644 --- a/docs/usage-examples/updateOne.txt +++ b/docs/usage-examples/updateOne.txt @@ -71,5 +71,6 @@ For instructions on editing your Laravel application to run the usage example, s .. tip:: To learn more about updating data with {+odm-short+}, see the `Updates - `__ section of the Laravel documentation. + `__ section of the + Laravel documentation. From 97187cdc97856e51290b36257d49dff53c37d9e0 Mon Sep 17 00:00:00 2001 From: norareidy Date: Mon, 25 Mar 2024 15:57:09 -0400 Subject: [PATCH 15/26] test file --- docs/usage-examples/updateOne.txt | 17 +++-------- tests/Models/Movie.php | 14 +++++++++ tests/UpdateOneTest.php | 48 +++++++++++++++++++++++++++++++ 3 files changed, 66 insertions(+), 13 deletions(-) create mode 100644 tests/Models/Movie.php create mode 100644 tests/UpdateOneTest.php diff --git a/docs/usage-examples/updateOne.txt b/docs/usage-examples/updateOne.txt index 3c0cb648c..ee335cc8b 100644 --- a/docs/usage-examples/updateOne.txt +++ b/docs/usage-examples/updateOne.txt @@ -44,20 +44,11 @@ The example calls the following methods on the ``Movie`` model: .. io-code-block:: :copyable: true - .. input:: + .. input:: ../../tests/UpdateOneTest.php + :start-after: begin-update-one + :end-before: end-update-one :language: php - - $updates = Movie::where('title', 'Carol') - ->orderBy('_id') - ->first() - ->update([ - "imdb" => [ - "rating" => 7.3, - "votes" => 142000 - ], - ]); - - echo "Updated documents: {$updates}"; + :dedent: .. output:: :language: console diff --git a/tests/Models/Movie.php b/tests/Models/Movie.php new file mode 100644 index 000000000..9fa7851d2 --- /dev/null +++ b/tests/Models/Movie.php @@ -0,0 +1,14 @@ +orderBy('_id') + ->first() + ->update([ + "imdb" => [ + "rating" => 7.3, + "votes" => 142000 + ], + ]); + + echo "Updated documents: {$updates}"; + // end-update-one + + // + } + + // ... + +} \ No newline at end of file From d9aa3c1d628e2795d9c96f2ded60563a21ab7c19 Mon Sep 17 00:00:00 2001 From: norareidy Date: Mon, 25 Mar 2024 17:30:41 -0400 Subject: [PATCH 16/26] move test file --- {tests/Models => docs/includes/usage-examples}/Movie.php | 0 {tests => docs/includes/usage-examples}/UpdateOneTest.php | 0 docs/usage-examples/updateOne.txt | 2 +- 3 files changed, 1 insertion(+), 1 deletion(-) rename {tests/Models => docs/includes/usage-examples}/Movie.php (100%) rename {tests => docs/includes/usage-examples}/UpdateOneTest.php (100%) diff --git a/tests/Models/Movie.php b/docs/includes/usage-examples/Movie.php similarity index 100% rename from tests/Models/Movie.php rename to docs/includes/usage-examples/Movie.php diff --git a/tests/UpdateOneTest.php b/docs/includes/usage-examples/UpdateOneTest.php similarity index 100% rename from tests/UpdateOneTest.php rename to docs/includes/usage-examples/UpdateOneTest.php diff --git a/docs/usage-examples/updateOne.txt b/docs/usage-examples/updateOne.txt index ee335cc8b..303466e59 100644 --- a/docs/usage-examples/updateOne.txt +++ b/docs/usage-examples/updateOne.txt @@ -44,7 +44,7 @@ The example calls the following methods on the ``Movie`` model: .. io-code-block:: :copyable: true - .. input:: ../../tests/UpdateOneTest.php + .. input:: ../includes/usage-examples/UpdateOneTest.php :start-after: begin-update-one :end-before: end-update-one :language: php From 0008e18cf2cdf63ee86bfb5d7cec9ce5eabde1a8 Mon Sep 17 00:00:00 2001 From: norareidy Date: Mon, 25 Mar 2024 17:32:07 -0400 Subject: [PATCH 17/26] single quotes --- docs/includes/usage-examples/UpdateOneTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/includes/usage-examples/UpdateOneTest.php b/docs/includes/usage-examples/UpdateOneTest.php index 050d8b889..e7602a4cf 100644 --- a/docs/includes/usage-examples/UpdateOneTest.php +++ b/docs/includes/usage-examples/UpdateOneTest.php @@ -36,8 +36,8 @@ public function updateOne(): void "votes" => 142000 ], ]); - - echo "Updated documents: {$updates}"; + + echo 'Updated documents: {$updates}'; // end-update-one // From cb103587111f7133e0df387f813683da8add71f0 Mon Sep 17 00:00:00 2001 From: norareidy Date: Tue, 26 Mar 2024 10:39:12 -0400 Subject: [PATCH 18/26] print syntax --- docs/includes/usage-examples/UpdateOneTest.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/docs/includes/usage-examples/UpdateOneTest.php b/docs/includes/usage-examples/UpdateOneTest.php index e7602a4cf..547484f39 100644 --- a/docs/includes/usage-examples/UpdateOneTest.php +++ b/docs/includes/usage-examples/UpdateOneTest.php @@ -31,13 +31,14 @@ public function updateOne(): void ->orderBy('_id') ->first() ->update([ - "imdb" => [ - "rating" => 7.3, - "votes" => 142000 + 'imdb' => [ + 'rating' => 7.3, + 'votes' => 142000 ], ]); - echo 'Updated documents: {$updates}'; + echo 'Updated documents: '; + echo $updates; // end-update-one // From 6c3d8512320cf79d4af1bbc54ab2e800af5198b6 Mon Sep 17 00:00:00 2001 From: norareidy Date: Tue, 26 Mar 2024 10:58:19 -0400 Subject: [PATCH 19/26] print statement again --- docs/includes/usage-examples/UpdateOneTest.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/docs/includes/usage-examples/UpdateOneTest.php b/docs/includes/usage-examples/UpdateOneTest.php index 547484f39..c3eff69df 100644 --- a/docs/includes/usage-examples/UpdateOneTest.php +++ b/docs/includes/usage-examples/UpdateOneTest.php @@ -37,8 +37,7 @@ public function updateOne(): void ], ]); - echo 'Updated documents: '; - echo $updates; + echo 'Updated documents: ' . $updates; // end-update-one // From f3ac9c8742cbbd3beee12c806e965b787f470893 Mon Sep 17 00:00:00 2001 From: norareidy Date: Tue, 26 Mar 2024 13:04:47 -0400 Subject: [PATCH 20/26] JT feedback --- docs/usage-examples/updateOne.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/usage-examples/updateOne.txt b/docs/usage-examples/updateOne.txt index 303466e59..f60bd3bad 100644 --- a/docs/usage-examples/updateOne.txt +++ b/docs/usage-examples/updateOne.txt @@ -21,8 +21,8 @@ You can update a document in a collection by retrieving a single document and ca the ``update()`` method on an Eloquent model or a query builder. Pass a query filter to the ``where()`` method, sort the matching documents, and call the -``first()`` method to match only one document. Then, update this matching document by passing -your intended document changes to the ``update()`` method. +``first()`` method to retrieve only the first document. Then, update this matching document +by passing your intended document changes to the ``update()`` method. Example ------- From b237a8653551d00e7db1afb0752ac966b74eb62e Mon Sep 17 00:00:00 2001 From: norareidy Date: Tue, 26 Mar 2024 17:05:35 +0000 Subject: [PATCH 21/26] apply phpcbf formatting --- docs/includes/usage-examples/Movie.php | 2 -- .../includes/usage-examples/UpdateOneTest.php | 26 ++++++------------- 2 files changed, 8 insertions(+), 20 deletions(-) diff --git a/docs/includes/usage-examples/Movie.php b/docs/includes/usage-examples/Movie.php index 9fa7851d2..728a066de 100644 --- a/docs/includes/usage-examples/Movie.php +++ b/docs/includes/usage-examples/Movie.php @@ -10,5 +10,3 @@ class Movie extends Model protected $collection = 'movies'; protected $fillable = ['title', 'year', 'runtime', 'imdb', 'plot']; } - - diff --git a/docs/includes/usage-examples/UpdateOneTest.php b/docs/includes/usage-examples/UpdateOneTest.php index c3eff69df..0c117fccb 100644 --- a/docs/includes/usage-examples/UpdateOneTest.php +++ b/docs/includes/usage-examples/UpdateOneTest.php @@ -4,45 +4,35 @@ namespace App\Http\Controllers; -use App\Models\Cargo; - use App\Models\Movie; - -use Illuminate\Database\Schema\Blueprint; -use Illuminate\Database\Schema\SQLiteBuilder; -use Illuminate\Support\Facades\Schema; use MongoDB\Laravel\Tests\TestCase; -use function assert; - class UpdateOneTest extends TestCase { - /** * @runInSeparateProcess * @preserveGlobalState disabled */ public function updateOne(): void { - require 'Models/Movie.php'; - + require 'Models/Movie.php'; + // begin-update-one - $updates = Movie::where('title', 'Carol') + $updates = Movie::where('title', 'Carol') ->orderBy('_id') ->first() ->update([ 'imdb' => [ 'rating' => 7.3, - 'votes' => 142000 + 'votes' => 142000, ], ]); - echo 'Updated documents: ' . $updates; + echo 'Updated documents: ' . $updates; // end-update-one - + // } - + // ... - -} \ No newline at end of file +} From 4856810e4b1b8274a3b9fceaeece841cc68eed87 Mon Sep 17 00:00:00 2001 From: norareidy Date: Tue, 26 Mar 2024 13:12:30 -0400 Subject: [PATCH 22/26] code --- docs/includes/usage-examples/UpdateOneTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/includes/usage-examples/UpdateOneTest.php b/docs/includes/usage-examples/UpdateOneTest.php index c3eff69df..fb06ee252 100644 --- a/docs/includes/usage-examples/UpdateOneTest.php +++ b/docs/includes/usage-examples/UpdateOneTest.php @@ -24,7 +24,7 @@ class UpdateOneTest extends TestCase */ public function updateOne(): void { - require 'Models/Movie.php'; + require_once __DIR__ . '/Movie.php'; // begin-update-one $updates = Movie::where('title', 'Carol') From d67827a6a13401af66d3d1d6340ca5d38255ec50 Mon Sep 17 00:00:00 2001 From: norareidy Date: Tue, 26 Mar 2024 17:14:06 +0000 Subject: [PATCH 23/26] apply phpcbf formatting --- docs/includes/usage-examples/UpdateOneTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/includes/usage-examples/UpdateOneTest.php b/docs/includes/usage-examples/UpdateOneTest.php index 06325f83c..296aeef55 100644 --- a/docs/includes/usage-examples/UpdateOneTest.php +++ b/docs/includes/usage-examples/UpdateOneTest.php @@ -15,8 +15,8 @@ class UpdateOneTest extends TestCase */ public function updateOne(): void { - require_once __DIR__ . '/Movie.php'; - + require_once __DIR__ . '/Movie.php'; + // begin-update-one $updates = Movie::where('title', 'Carol') ->orderBy('_id') From abab190c1d8f80104ae311cc137690c551d92e5d Mon Sep 17 00:00:00 2001 From: norareidy Date: Thu, 28 Mar 2024 17:03:03 -0400 Subject: [PATCH 24/26] JT feedback --- docs/includes/usage-examples/UpdateOneTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/includes/usage-examples/UpdateOneTest.php b/docs/includes/usage-examples/UpdateOneTest.php index 06325f83c..b2406f32c 100644 --- a/docs/includes/usage-examples/UpdateOneTest.php +++ b/docs/includes/usage-examples/UpdateOneTest.php @@ -13,7 +13,7 @@ class UpdateOneTest extends TestCase * @runInSeparateProcess * @preserveGlobalState disabled */ - public function updateOne(): void + public function testUpdateOne(): void { require_once __DIR__ . '/Movie.php'; From 2fb18a5cf52bb7f5d5582d1acae46081661e5084 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Tamarelle?= Date: Wed, 3 Apr 2024 00:03:51 +0200 Subject: [PATCH 25/26] Fix UpdateOneTest example --- .../includes/usage-examples/UpdateOneTest.php | 36 ++++++++++++------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/docs/includes/usage-examples/UpdateOneTest.php b/docs/includes/usage-examples/UpdateOneTest.php index 7d544f98b..e1f864170 100644 --- a/docs/includes/usage-examples/UpdateOneTest.php +++ b/docs/includes/usage-examples/UpdateOneTest.php @@ -17,22 +17,32 @@ public function testUpdateOne(): void { require_once __DIR__ . '/Movie.php'; - // begin-update-one + Movie::truncate(); + Movie::insert([ + [ + 'title' => 'Carol', + 'imdb' => [ + 'rating' => 7.2, + 'votes' => 125000, + ], + ], + ]); + + // begin-update-one $updates = Movie::where('title', 'Carol') - ->orderBy('_id') - ->first() - ->update([ - 'imdb' => [ - 'rating' => 7.3, - 'votes' => 142000, - ], - ]); + ->orderBy('_id') + ->first() + ->update([ + 'imdb' => [ + 'rating' => 7.3, + 'votes' => 142000, + ], + ]); echo 'Updated documents: ' . $updates; - // end-update-one + // end-update-one - // + $this->assertTrue($updates); + $this->expectOutputString('Updated documents: 1'); } - - // ... } From 1c90a2865c72e42407410b88c339f274611d2fc4 Mon Sep 17 00:00:00 2001 From: norareidy Date: Wed, 3 Apr 2024 10:46:58 -0400 Subject: [PATCH 26/26] add to TOC --- docs/usage-examples.txt | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/docs/usage-examples.txt b/docs/usage-examples.txt index bf14bba4a..08dda77ea 100644 --- a/docs/usage-examples.txt +++ b/docs/usage-examples.txt @@ -65,4 +65,10 @@ a result. To run the operation, you can copy the sample code to a controller end Laravel application. To view the expected output of the operation, you can add a web route to your application that -calls the controller function and returns the result to a web interface. \ No newline at end of file +calls the controller function and returns the result to a web interface. + +.. toctree:: + :titlesonly: + :maxdepth: 1 + + /usage-examples/updateOne \ No newline at end of file