@@ -53,6 +53,36 @@ collection.
53
53
54
54
To learn more about query filters, see the :ref:`kotlin-sync-specify-query` guide.
55
55
56
+ Find One Document Example
57
+ ~~~~~~~~~~~~~~~~~~~~~~~~~
58
+
59
+ The following example chains the ``first()`` method to the ``find()`` method call to find
60
+ the first document in which the value of the ``cuisine`` field is ``"Spanish"``:
61
+
62
+ .. literalinclude:: /includes/read/retrieve.kt
63
+ :start-after: start-find-one
64
+ :end-before: end-find-one
65
+ :language: kotlin
66
+ :copyable:
67
+ :dedent:
68
+
69
+ The ``find()`` operation in the preceding example returns a MongoDB document, which you
70
+ can print, as shown in the following example:
71
+
72
+ .. io-code-block::
73
+ :copyable: true
74
+
75
+ .. input:: /includes/read/retrieve.kt
76
+ :start-after: start-find-one-print
77
+ :end-before: end-find-one-print
78
+ :language: kotlin
79
+ :dedent:
80
+
81
+ .. output::
82
+ :visible: false
83
+
84
+ Restaurant(name=Tropicoso Club, cuisine=Spanish)
85
+
56
86
Find Documents Example
57
87
~~~~~~~~~~~~~~~~~~~~~~
58
88
@@ -124,6 +154,13 @@ modifying queries:
124
154
- | Specifies a string to attach to the query. This can help you trace and interpret the
125
155
operation in the server logs and in profile data.
126
156
157
+ * - ``first()``
158
+ - | Returns the first document that matches the query or throws a ``MongoClientException``
159
+ if no matching documents exist.
160
+
161
+ * - ``firstOrNull()``
162
+ - | Returns the first document that matches the query or ``null`` if no matching documents exist.
163
+
127
164
* - ``hint()``
128
165
- | Specifies the index to use for the query.
129
166
0 commit comments