@@ -62,8 +62,8 @@ consist of the ``Find()`` and ``FindOne()`` methods.
62
62
63
63
.. _golang-find-example:
64
64
65
- Find All Documents
66
- ~~~~~~~~~~~~~~~~~~
65
+ Find Multiple Documents
66
+ ~~~~~~~~~~~~~~~~~~~~~~~
67
67
68
68
The ``Find()`` method expects you to pass a ``Context`` type and a
69
69
query filter. The method returns *all* documents that match the filter
@@ -94,6 +94,33 @@ the ``Find()`` method, which performs the following actions:
94
94
95
95
To learn how to access data by using a cursor, see the :ref:`golang-cursor` guide.
96
96
97
+ Find Multiple Documents Example: Full File
98
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
99
+
100
+ .. include:: /includes/usage-examples/example-intro.rst
101
+
102
+ The following example finds all documents in the ``restaurants`` collection
103
+ in which the value of ``cuisine`` is ``"Italian"``. The example returns a cursor that
104
+ references the matched documents and unpacks the documents into a slice:
105
+
106
+ .. io-code-block::
107
+ :copyable: true
108
+
109
+ .. input:: /includes/usage-examples/code-snippets/find.go
110
+ :language: go
111
+ :dedent:
112
+
113
+ .. output::
114
+ :language: none
115
+ :visible: false
116
+
117
+ // results truncated
118
+ ...
119
+ { ... , "Name" : "Epistrophy Cafe", "RestaurantId": "41117553", "Cuisine" : "Italian", ... },
120
+ { ... , "Name" : "Remi", "RestaurantId": "41118090", "Cuisine" : "Italian", ... },
121
+ { ... , "Name" : "Sant Ambroeus", "RestaurantId": "41120682", "Cuisine" : "Italian", ... },
122
+ ...
123
+
97
124
.. _golang-find-one-example:
98
125
99
126
Find One Document
@@ -182,6 +209,36 @@ as parameters to the ``FindOne()`` method to perform the following actions:
182
209
about the ``_id`` field, see the :ref:`_id Field <golang-insert-id>`
183
210
section of the Insert a Document page.
184
211
212
+ Find One Document Example: Full File
213
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
214
+
215
+ .. include:: /includes/usage-examples/example-intro.rst
216
+
217
+ The following example finds and returns the first document in the
218
+ ``restaurants`` collection in which the value of ``name`` is ``"Bagels N Buns"``:
219
+
220
+ .. io-code-block::
221
+ :copyable: true
222
+
223
+ .. input:: /includes/usage-examples/code-snippets/findOne.go
224
+ :language: go
225
+ :dedent:
226
+
227
+ .. output::
228
+ :language: none
229
+ :visible: false
230
+
231
+ // results truncated
232
+ {
233
+ "ID": "5eb3d668b31de5d588f42950",
234
+ "Name": "Bagels N Buns",
235
+ "RestaurantId": "40363427"
236
+ "Address": [...],
237
+ "Borough": "Staten Island",
238
+ "Cuisine": "Delicatessen",
239
+ "Grades": [...]
240
+ }
241
+
185
242
.. _golang-retrieve-options:
186
243
187
244
Modify Behavior
@@ -330,20 +387,12 @@ the MongoDB server manual page on :manual:`Aggregation
330
387
Additional Information
331
388
----------------------
332
389
333
- For runnable examples of the find operations, see the following usage
334
- examples:
335
-
336
- - :ref:`golang-find-one`
337
- - :ref:`golang-find-multiple`
338
-
339
390
To learn more about the operations mentioned, see the following
340
391
guides:
341
392
342
393
- :ref:`golang-query-document`
343
394
- :ref:`golang-cursor`
344
- - :ref:`golang-skip`
345
- - :ref:`golang-sort-results`
346
- - :ref:`golang-limit`
395
+ - :ref:`Specify Documents to Return <golang-specify-documents-to-return>`
347
396
- :ref:`golang-project`
348
397
- :ref:`golang-aggregation`
349
398
- :ref:`golang-collations`
0 commit comments