Skip to content

Commit 19ed7ae

Browse files
committed
wip
1 parent e2fb9fc commit 19ed7ae

File tree

4 files changed

+189
-72
lines changed

4 files changed

+189
-72
lines changed

Diff for: docs/includes/usage-examples/DeleteOneTest.php

+14-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
use App\Models\Movie;
88
use MongoDB\Laravel\Tests\TestCase;
9+
use Illuminate\Database\Query\Builder;
10+
use Illuminate\Support\Facades\DB;
911

1012
class DeleteOneTest extends TestCase
1113
{
@@ -25,14 +27,24 @@ public function testDeleteOne(): void
2527
],
2628
]);
2729

28-
// begin-delete-one
30+
// begin-eloquent-delete-one
2931
$deleted = Movie::where('title', 'Quiz Show')
3032
->orderBy('_id')
3133
->limit(1)
3234
->delete();
3335

3436
echo 'Deleted documents: ' . $deleted;
35-
// end-delete-one
37+
// end-eloquent-delete-one
38+
39+
// begin-qb-delete-one
40+
$deleted = DB::table('movies')
41+
->where('title', 'Quiz Show')
42+
->orderBy('_id')
43+
->limit(1)
44+
->delete();
45+
46+
echo 'Deleted documents: ' . $deleted;
47+
// end-qb-delete-one
3648

3749
$this->assertEquals(1, $deleted);
3850
$this->expectOutputString('Deleted documents: 1');

Diff for: docs/includes/usage-examples/DistinctTest.php

+14-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
use App\Models\Movie;
88
use MongoDB\Laravel\Tests\TestCase;
9+
use Illuminate\Database\Query\Builder;
10+
use Illuminate\Support\Facades\DB;
911

1012
class DistinctTest extends TestCase
1113
{
@@ -45,14 +47,24 @@ public function testDistinct(): void
4547
],
4648
]);
4749

48-
// begin-distinct
50+
// begin-eloquent-distinct
4951
$ratings = Movie::where('directors', 'Sofia Coppola')
5052
->select('imdb.rating')
5153
->distinct()
5254
->get();
5355

5456
echo $ratings;
55-
// end-distinct
57+
// end-eloquent-distinct
58+
59+
// begin-qb-distinct
60+
$ratings = DB::table('movies')
61+
->where('directors', 'Sofia Coppola')
62+
->select('imdb.rating')
63+
->distinct()
64+
->get();
65+
66+
echo $ratings;
67+
// end-qb-distinct
5668

5769
$this->expectOutputString('[[6.4],[7.8]]');
5870
}

Diff for: docs/usage-examples/deleteOne.txt

+72-28
Original file line numberDiff line numberDiff line change
@@ -35,33 +35,77 @@ the ``delete()`` method.
3535
Example
3636
-------
3737

38-
This usage example performs the following actions:
39-
40-
- Uses the ``Movie`` Eloquent model to represent the ``movies`` collection in the
41-
``sample_mflix`` database
42-
- Deletes a document from the ``movies`` collection that matches a query filter
43-
- Prints the number of deleted documents
44-
45-
The example calls the following methods on the ``Movie`` model:
46-
47-
- ``where()``: matches documents in which the value of the ``title`` field is ``"Quiz Show"``
48-
- ``orderBy()``: sorts matched documents by their ascending ``_id`` values
49-
- ``limit()``: retrieves only the first matching document
50-
- ``delete()``: deletes the retrieved document
51-
52-
.. io-code-block::
53-
:copyable: true
54-
55-
.. input:: ../includes/usage-examples/DeleteOneTest.php
56-
:start-after: begin-delete-one
57-
:end-before: end-delete-one
58-
:language: php
59-
:dedent:
60-
61-
.. output::
62-
:language: console
63-
:visible: false
64-
65-
Deleted documents: 1
38+
Select from the following :guilabel:`Eloquent` and :guilabel:`Query
39+
Builder` tabs to view usage examples for the same operation that use
40+
each corresponding query syntax:
41+
42+
.. tabs::
43+
44+
.. tab:: Eloquent
45+
:tabid: eloquent-model-count
46+
47+
This example performs the following actions:
48+
49+
- Uses the ``Movie`` Eloquent model to represent the ``movies``
50+
collection in the ``sample_mflix`` database
51+
- Deletes a document from the ``movies`` collection that matches a
52+
query filter
53+
- Prints the number of deleted documents
54+
55+
The example calls the following methods on the ``Movie`` model:
56+
57+
- ``where()``: Matches documents in which the value of the
58+
``title`` field is ``"Quiz Show"``
59+
- ``orderBy()``: Sorts matched documents by their ascending ``_id`` values
60+
- ``limit()``: Retrieves only the first matching document
61+
- ``delete()``: Deletes the retrieved document
62+
63+
.. io-code-block::
64+
:copyable: true
65+
66+
.. input:: ../includes/usage-examples/DeleteOneTest.php
67+
:start-after: begin-eloquent-delete-one
68+
:end-before: end-eloquent-delete-one
69+
:language: php
70+
:dedent:
71+
72+
.. output::
73+
:language: console
74+
:visible: false
75+
76+
Deleted documents: 1
77+
78+
.. tab:: Query Builder
79+
:tabid: query-builder-count
80+
81+
This example performs the following actions:
82+
83+
- Accesses the ``movies`` collection by calling the ``table()``
84+
method from the ``DB`` facade
85+
- Deletes a document from the ``movies`` collection that matches a
86+
query filter
87+
- Prints the number of deleted documents
88+
89+
The example calls the following query builder methods:
90+
91+
- ``where()``: Matches documents in which the value of the
92+
``title`` field is ``"Quiz Show"``
93+
- ``orderBy()``: Sorts matched documents by their ascending ``_id`` values
94+
- ``limit()``: Retrieves only the first matching document
95+
- ``delete()``: Deletes the retrieved document
96+
97+
.. io-code-block::
98+
99+
.. input:: ../includes/usage-examples/DeleteOneTest.php
100+
:start-after: begin-qb-delete-one
101+
:end-before: end-qb-delete-one
102+
:language: php
103+
:dedent:
104+
105+
.. output::
106+
:language: console
107+
:visible: false
108+
109+
Deleted documents: 1
66110

67111
.. include:: /includes/usage-examples/fact-edit-laravel-app.rst

Diff for: docs/usage-examples/distinct.txt

+89-40
Original file line numberDiff line numberDiff line change
@@ -17,50 +17,99 @@ Retrieve Distinct Field Values
1717
:depth: 1
1818
:class: singlecol
1919

20-
You can retrieve distinct field values of documents in a collection by calling the ``distinct()``
21-
method on an object collection or a query builder.
20+
You can retrieve distinct field values of documents in a collection by
21+
calling the ``distinct()`` method on an object collection or a query
22+
builder.
2223

23-
To retrieve distinct field values, pass a query filter to the ``where()`` method and a field name
24-
to the ``select()`` method. Then, call ``distinct()`` to return the unique values of the selected
25-
field in documents that match the query filter.
24+
To retrieve distinct field values, pass a query filter to the
25+
``where()`` method and a field name to the ``select()`` method. Then,
26+
call ``distinct()`` to return the unique values of the selected field in
27+
documents that match the query filter.
2628

27-
Example
28-
-------
29-
30-
This usage example performs the following actions:
31-
32-
- Uses the ``Movie`` Eloquent model to represent the ``movies`` collection in the
33-
``sample_mflix`` database
34-
- Retrieves distinct field values of documents from the ``movies`` collection that match a query filter
35-
- Prints the distinct values
36-
37-
The example calls the following methods on the ``Movie`` model:
38-
39-
- ``where()``: matches documents in which the value of the ``directors`` field includes ``"Sofia Coppola"``.
40-
- ``select()``: retrieves the matching documents' ``imdb.rating`` field values.
41-
- ``distinct()``: retrieves the unique values of the selected field and returns
42-
the list of values.
43-
- ``get()``: retrieves the query results.
44-
45-
.. io-code-block::
46-
:copyable: true
29+
.. tip::
4730

48-
.. input:: ../includes/usage-examples/DistinctTest.php
49-
:start-after: begin-distinct
50-
:end-before: end-distinct
51-
:language: php
52-
:dedent:
31+
For more information about query filters, see the
32+
:ref:`laravel-retrieve-matching` section of the Read Operations
33+
guide.
5334

54-
.. output::
55-
:language: console
56-
:visible: false
35+
Example
36+
-------
5737

58-
[[5.6],[6.4],[7.2],[7.8]]
38+
Select from the following :guilabel:`Eloquent` and :guilabel:`Query
39+
Builder` tabs to view usage examples for the same operation that use
40+
each corresponding query syntax:
41+
42+
.. tabs::
43+
44+
.. tab:: Eloquent
45+
:tabid: eloquent-model-count
46+
47+
This example performs the following actions:
48+
49+
- Uses the ``Movie`` Eloquent model to represent the ``movies``
50+
collection in the ``sample_mflix`` database
51+
- Retrieves distinct field values of documents from the ``movies``
52+
collection that match a query filter
53+
- Prints the distinct values
54+
55+
The example calls the following methods on the ``Movie`` model:
56+
57+
- ``where()``: Matches documents in which the value of the
58+
``directors`` field includes ``"Sofia Coppola"``
59+
- ``select()``: Retrieves the matching documents' ``imdb.rating``
60+
field values
61+
- ``distinct()``: Retrieves the unique values of the selected
62+
field and returns the list of values
63+
- ``get()``: Retrieves the query results
64+
65+
.. io-code-block::
66+
:copyable: true
67+
68+
.. input:: ../includes/usage-examples/DistinctTest.php
69+
:start-after: begin-eloquent-distinct
70+
:end-before: end-eloquent-distinct
71+
:language: php
72+
:dedent:
73+
74+
.. output::
75+
:language: console
76+
:visible: false
77+
78+
[[5.6],[6.4],[7.2],[7.8]]
79+
80+
.. tab:: Query Builder
81+
:tabid: query-builder-count
82+
83+
This example performs the following actions:
84+
85+
- Accesses the ``movies`` collection by calling the ``table()``
86+
method from the ``DB`` facade
87+
- Retrieves distinct field values of documents from the ``movies``
88+
collection that match a query filter
89+
- Prints the distinct values
90+
91+
The example calls the following query builder methods:
92+
93+
- ``where()``: Matches documents in which the value of the
94+
``directors`` field includes ``"Sofia Coppola"``
95+
- ``select()``: Retrieves the matching documents' ``imdb.rating``
96+
field values
97+
- ``distinct()``: Retrieves the unique values of the selected
98+
field and returns the list of values
99+
- ``get()``: Retrieves the query results
100+
101+
.. io-code-block::
102+
103+
.. input:: ../includes/usage-examples/DistinctTest.php
104+
:start-after: begin-qb-distinct
105+
:end-before: end-qb-distinct
106+
:language: php
107+
:dedent:
108+
109+
.. output::
110+
:language: console
111+
:visible: false
112+
113+
[[5.6],[6.4],[7.2],[7.8]]
59114

60115
.. include:: /includes/usage-examples/fact-edit-laravel-app.rst
61-
62-
.. tip::
63-
64-
For more information about query filters, see the :ref:`laravel-retrieve-matching` section of
65-
the Read Operations guide.
66-

0 commit comments

Comments
 (0)