@@ -36,22 +36,150 @@ methods that you can use to read data from MongoDB by using
36
36
To learn more about any of the methods included in this guide,
37
37
see the links provided in each section.
38
38
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.
41
72
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
43
80
collection:
44
81
45
82
.. code-block:: php
46
-
47
- SampleModel::create([
48
- '<field name>' => '<value>',
49
- '<field name>' => '<value>',
50
- ...
51
- ]);
52
83
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();
55
183
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.
0 commit comments