Skip to content

Commit

Permalink
adding callout + text
Browse files Browse the repository at this point in the history
  • Loading branch information
norareidy committed Sep 29, 2023
1 parent 4d6b716 commit 4299edc
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions source/fundamentals/crud/read-operations/retrieve.txt
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ The ``Find()`` method expects you to pass a ``Context`` type and a
query filter. The method returns *all* documents that match the filter
as a ``Cursor`` type.

To learn how to access data in a cursor, see :ref:`golang-cursor`.
For a ``Find()`` method code example, see :ref:`golang-find-example` on
this page. To learn how to access data in a cursor, see :ref:`golang-cursor`.

Find One Document
~~~~~~~~~~~~~~~~~
Expand All @@ -75,7 +76,12 @@ The ``FindOne()`` method expects you to pass a ``Context`` type and a
query filter. The method returns *the first document* that matches the
filter as a ``SingleResult`` type.

To learn how to access data in a ``SingleResult`` see :ref:`golang-bson-unmarshalling`.
For a ``FindOne()`` method code example, see :ref:`golang-find-one-example`
on this page. For a ``FindOne()`` code example that queries for a specified
ObjectId value, see :ref:`golang-find-one-by-id` on this page.

To learn how to access data in a ``SingleResult``, see
:ref:`golang-bson-unmarshalling` in the BSON guide.

.. _golang-retrieve-options:

Expand Down Expand Up @@ -122,6 +128,8 @@ following methods:
- | The field and type of sort to order the matched documents. You can specify an ascending or descending sort.
| Default: none

.. _golang-find-example:

Find Example
````````````

Expand Down Expand Up @@ -169,6 +177,8 @@ the ``Find()`` method, which performs the following actions:
{"Item":"Sencha","Rating":7,"DateOrdered":"2009-11-18T05:00:00Z"}
{"Item":"Masala","Rating":8,"DateOrdered":"2009-12-01T05:00:00Z"}

.. _golang-find-one-example:

Find One Example
````````````````

Expand Down Expand Up @@ -203,10 +213,10 @@ to the ``FindOne()`` method, which performs the following actions:

{"Item":"Masala","Rating":9,"DateOrdered":"2009-11-12T05:00:00Z"}

.. _golang-find-by-id:
.. _golang-find-one-by-id:

Find by Object ID Example
`````````````````````````
Find One by Object ID Example
`````````````````````````````

The following example defines an ``id`` variable with an ``ObjectId``
value and passes a context, filter, and ``FindOneOptions`` to the
Expand Down Expand Up @@ -245,6 +255,13 @@ value and passes a context, filter, and ``FindOneOptions`` to the

[{"Key":"item","Value":"Hibiscus"},{"Key":"rating","Value":4}]

.. note::

The {+driver-short+} automatically generates a unique ``ObjectId`` value for
each document's ``_id`` field. The preceding code example uses an ``ObjectID``
with a hexidecimal string representation of ``"65170b42b99efdd0b07d42de"``,
but your ``ObjectID`` values are unique.

.. _golang-retrieve-aggregation:

Aggregation Operations
Expand Down

0 comments on commit 4299edc

Please sign in to comment.