Skip to content

Commit d5bc8d4

Browse files
committed
skip
1 parent b28cf9b commit d5bc8d4

File tree

2 files changed

+151
-13
lines changed

2 files changed

+151
-13
lines changed

docs/fundamentals/read-operations.txt

Lines changed: 141 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,22 +36,150 @@ methods that you can use to read data from MongoDB by using
3636
To learn more about any of the methods included in this guide,
3737
see the links provided in each section.
3838

39-
Insert One
40-
----------
39+
Find One
40+
--------
41+
42+
The following code shows how to retrieve the first matching document
43+
from a collection:
44+
45+
.. code-block:: php
46+
47+
SampleModel::where('<field name>', <value>)
48+
->first();
49+
50+
To view a runnable example that finds one document, see the
51+
:ref:`laravel-find-one-usage` usage example.
52+
53+
To learn more about retrieving documents, see the
54+
:ref:`laravel-fundamentals-read-retrieve` guide.
55+
56+
To learn more about the ``first()`` method, see the
57+
:ref:`laravel-fundamentals-read-retrieve` guide.
58+
59+
Find Multiple
60+
-------------
61+
62+
The following code shows how to retrieve all documents that match a
63+
query filter from a collection:
64+
65+
.. code-block:: php
66+
67+
SampleModel::where('<field name>', <value>)
68+
->get();
69+
70+
To view a runnable example that finds documents, see the
71+
:ref:`laravel-find-usage` usage example.
4172

42-
The following code shows how to insert a single document into a
73+
To learn more about retrieving documents, see the
74+
:ref:`laravel-fundamentals-read-retrieve` guide.
75+
76+
Return All Documents
77+
--------------------
78+
79+
The following code shows how to retrieve all documents from a
4380
collection:
4481

4582
.. code-block:: php
46-
47-
SampleModel::create([
48-
'<field name>' => '<value>',
49-
'<field name>' => '<value>',
50-
...
51-
]);
5283

53-
To view a runnable example that inserts one document, see the
54-
:ref:`laravel-insert-one-usage` usage example.
84+
SampleModel::get();
85+
86+
/* Or, use the all() method. */
87+
88+
SampleModel::all();
89+
90+
To view a runnable example that finds documents, see the
91+
:ref:`laravel-find-usage` usage example.
92+
93+
To learn more about retrieving documents, see the
94+
:ref:`laravel-fundamentals-read-retrieve` guide.
95+
96+
Search Text
97+
-----------
98+
99+
The following code shows how to perform a full-text search on a string
100+
field in a collection's documents:
101+
102+
.. code-block:: php
103+
104+
SampleModel::where('$text', ['$search' => '<search term or phrase>'])
105+
->get();
106+
107+
To learn more about searching on text fields, see the
108+
:ref:`laravel-retrieve-text-search` guide.
109+
110+
Count Documents in a Collection
111+
-------------------------------
112+
113+
The following code shows how to count documents in a collection:
114+
115+
.. code-block:: php
116+
117+
SampleModel::count();
118+
119+
/* You can also count documents that match a filter. */
120+
121+
SampleModel::where('<field name>', '<value>')
122+
->count();
123+
124+
To view a runnable example that counts documents, see the
125+
:ref:`laravel-count-usage` usage example.
126+
127+
Retrieve Distinct Values
128+
------------------------
129+
130+
The following code shows how to retrieve the distinct values of a
131+
specified field:
132+
133+
.. code-block:: php
134+
135+
SampleModel::select('<field name>')
136+
->distinct()
137+
->get();
138+
139+
To view a runnable example that returns distinct field values, see the
140+
:ref:`laravel-distinct-usage` usage example.
141+
142+
Skip Results
143+
------------
144+
145+
The following code shows how to skip a specified number of documents
146+
returned from MongoDB:
147+
148+
.. code-block:: php
149+
150+
SampleModel::where('<field name>', '<value>')
151+
->skip(<number to skip>)
152+
->get();
153+
154+
To learn more about modifying how {+odm-long+} returns results, see the
155+
:ref:`laravel-read-modify-results` guide.
156+
157+
Limit Results
158+
-------------
159+
160+
The following code shows how to return only a specified number of
161+
documents from MongoDB:
162+
163+
.. code-block:: php
164+
165+
SampleModel::where('<field name>', '<value>')
166+
->take(<number to return>)
167+
->get();
168+
169+
To learn more about modifying how {+odm-long+} returns results, see the
170+
:ref:`laravel-read-modify-results` guide.
171+
172+
Sort Results
173+
------------
174+
175+
The following code shows how to set a sort order on results returned
176+
from MongoDB:
177+
178+
.. code-block:: php
179+
180+
Movie::where('field name', '<value>')
181+
->orderBy('<field to sort on>')
182+
->get();
55183

56-
To learn more about inserting documents, see the
57-
:ref:`laravel-fundamentals-write-insert` guide.
184+
To learn more about modifying how {+odm-long+} returns results, see the
185+
:ref:`laravel-read-modify-results` guide.

docs/fundamentals/read-operations/retrieve.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,13 @@ To retrieve documents that match a set of criteria, call the ``where()``
4444
method on the collection's corresponding Eloquent model, then pass a query
4545
filter to the method.
4646

47+
.. tip:: Retrieve One Document
48+
49+
The ``where()`` method retrieves all matching documents. To retrieve
50+
the first matching document, you can chain the ``first()`` method. To
51+
learn more and view an example, see the :ref:`laravel-retrieve-one`
52+
section of the Modify Query Results guide.
53+
4754
A query filter specifies field value requirements and instructs the find
4855
operation to return only documents that meet these requirements.
4956

@@ -221,3 +228,6 @@ operations by using the {+odm-short+}, see the following usage examples:
221228

222229
To learn how to insert data into MongoDB, see the
223230
:ref:`laravel-fundamentals-write-ops` guide.
231+
232+
To learn how to modify the way that the {+odm-short+} returns results,
233+
see the :ref:`laravel-read-modify-results` guide.

0 commit comments

Comments
 (0)