Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
rustagir committed Jan 31, 2025
1 parent 79035d5 commit e558e60
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 104 deletions.
1 change: 1 addition & 0 deletions docs/includes/usage-examples/FindOneTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}
1 change: 1 addition & 0 deletions docs/includes/usage-examples/InsertOneTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}
21 changes: 1 addition & 20 deletions docs/includes/usage-examples/UpdateOneTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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');
}
}
11 changes: 2 additions & 9 deletions docs/usage-examples/findOne.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand All @@ -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
106 changes: 31 additions & 75 deletions docs/usage-examples/updateOne.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit e558e60

Please sign in to comment.