@@ -29,62 +29,121 @@ Find Multiple Documents
2929
3030Pass a query filter to the ``where()`` method to retrieve documents that meet a
3131set of criteria. When you call the ``get()`` method, MongoDB returns the
32- matching documents according to their :term:`natural order` in the database or
32+ matching documents according to their :term:`natural order` in the collection or
3333according to the sort order that you can specify by using the ``orderBy()``
3434method.
3535
36- To learn more about query builder methods, see the :ref:`laravel-query-builder`
37- guide.
36+ .. tip::
37+
38+ To learn about other ways to retrieve documents with the
39+ {+odm-short+}, see the :ref:`laravel-fundamentals-retrieve` guide.
3840
3941Example
4042-------
4143
42- This usage example performs the following actions:
43-
44- - Uses the ``Movie`` Eloquent model to represent the ``movies`` collection in the
45- ``sample_mflix`` database
46- - Retrieves and prints documents from the ``movies`` collection that match a query filter
47-
48- The example calls the following methods on the ``Movie`` model:
49-
50- - ``where()``: matches documents in which the value of the ``runtime`` field is greater than ``900``
51- - ``orderBy()``: sorts matched documents by their ascending ``_id`` values
52- - ``get()``: retrieves the query results as a Laravel collection object
53-
54- .. io-code-block::
55- :copyable: true
56-
57- .. input:: ../includes/usage-examples/FindManyTest.php
58- :start-after: begin-find
59- :end-before: end-find
60- :language: php
61- :dedent:
62-
63- .. output::
64- :language: json
65- :visible: false
66-
67- // Results are truncated
68-
69- [
70- {
71- "_id": ...,
72- "runtime": 1256,
73- "title": "Centennial",
74- ...,
75- },
76- {
77- "_id": ...,
78- "runtime": 1140,
79- "title": "Baseball",
80- ...,
81- },
82- ...
83- ]
44+ Select from the following :guilabel:`Eloquent` and :guilabel:`Query
45+ Builder` tabs to view usage examples for the same operation that use
46+ each corresponding query syntax:
47+
48+ .. tabs::
49+
50+ .. tab:: Eloquent
51+ :tabid: eloquent-model-count
52+
53+ This example performs the following actions:
54+
55+ - Uses the ``Movie`` Eloquent model to represent the ``movies``
56+ collection in the ``sample_mflix`` database
57+ - Retrieves and prints documents from the ``movies`` collection
58+ that match a query filter
59+
60+ The example calls the following methods on the ``Movie`` model:
61+
62+ - ``where()``: Matches documents in which the value of the
63+ ``runtime`` field is greater than ``900``
64+ - ``orderBy()``: Sorts matched documents by their ascending
65+ ``_id`` values
66+ - ``get()``: Retrieves the query results as a Laravel collection
67+ object
68+
69+ .. io-code-block::
70+ :copyable: true
71+
72+ .. input:: ../includes/usage-examples/FindManyTest.php
73+ :start-after: begin-eloquent-find
74+ :end-before: end-eloquent-find
75+ :language: php
76+ :dedent:
77+
78+ .. output::
79+ :language: console
80+ :visible: false
81+
82+ // Results are truncated
83+
84+ [
85+ {
86+ "_id": ...,
87+ "runtime": 1256,
88+ "title": "Centennial",
89+ ...,
90+ },
91+ {
92+ "_id": ...,
93+ "runtime": 1140,
94+ "title": "Baseball",
95+ ...,
96+ },
97+ ...
98+ ]
99+
100+ .. tab:: Query Builder
101+ :tabid: query-builder-count
102+
103+ This example performs the following actions:
104+
105+ - Accesses the ``movies`` collection by calling the ``table()``
106+ method from the ``DB`` facade
107+ - Retrieves and prints documents from the ``movies`` collection
108+ that match a query filter
109+
110+ The example calls the following query builder methods:
111+
112+ - ``where()``: Matches documents in which the value of the
113+ ``runtime`` field is greater than ``900``
114+ - ``orderBy()``: Sorts matched documents by their ascending
115+ ``_id`` values
116+ - ``get()``: Retrieves the query results as a Laravel collection
117+ object
118+
119+ .. io-code-block::
120+
121+ .. input:: ../includes/usage-examples/FindManyTest.php
122+ :start-after: begin-qb-find
123+ :end-before: end-qb-find
124+ :language: php
125+ :dedent:
126+
127+ .. output::
128+ :language: console
129+ :visible: false
130+
131+ // Results are truncated
132+
133+ [
134+ {
135+ "_id": ...,
136+ "runtime": 1256,
137+ "title": "Centennial",
138+ ...,
139+ },
140+ {
141+ "_id": ...,
142+ "runtime": 1140,
143+ "title": "Baseball",
144+ ...,
145+ },
146+ ...
147+ ]
84148
85149.. include:: /includes/usage-examples/fact-edit-laravel-app.rst
86-
87- .. tip::
88-
89- To learn about other ways to retrieve documents with the {+odm-short+}, see the
90- :ref:`laravel-fundamentals-retrieve` guide.
0 commit comments