@@ -31,6 +31,14 @@ database from the :atlas:`Atlas sample datasets </sample-data>`. To learn how to
3131free MongoDB Atlas cluster and load the sample datasets, see the
3232:atlas:`Get Started with Atlas </getting-started>` guide.
3333
34+ The following {+language+} data class models the documents in this collection:
35+
36+ .. literalinclude:: /includes/read/count.kt
37+ :start-after: start-data-class
38+ :end-before: end-data-class
39+ :language: kotlin
40+ :copyable:
41+
3442.. _kotlin-sync-accurate-count:
3543
3644Retrieve an Accurate Count
@@ -40,7 +48,7 @@ Use the ``countDocuments()`` method to count the number of documents that are in
4048collection. To count the number of documents that match specified search
4149critera, pass a query filter to the ``countDocuments()`` method.
4250
43- .. TODO: To learn more about specifying a query, see :ref:`kotlin-sync-specify-query`.
51+ To learn more about specifying a query, see :ref:`kotlin-sync-specify-query`.
4452
4553Count All Documents
4654~~~~~~~~~~~~~~~~~~~
@@ -50,10 +58,11 @@ with no arguments, as shown in the following example:
5058
5159.. io-code-block::
5260
53- .. input::
61+ .. input:: /includes/read/count.kt
62+ :start-after: start-count-all
63+ :end-before: end-count-all
5464 :language: kotlin
55-
56- print(collection.countDocuments())
65+ :dedent:
5766
5867 .. output::
5968 :visible: false
@@ -69,10 +78,11 @@ in the ``movies`` collection that have a ``year`` field value equal to ``1930``:
6978
7079.. io-code-block::
7180
72- .. input::
73- :language: kotlin
74-
75- print(collection.countDocuments(eq("year", "1930")))
81+ .. input:: /includes/read/count.kt
82+ :start-after: start-count-query
83+ :end-before: end-count-query
84+ :language: kotlin
85+ :dedent:
7686
7787 .. output::
7888 :visible: false
@@ -99,30 +109,33 @@ The following table describes the options you can set to customize ``countDocume
99109 - Description
100110
101111 * - ``comment``
102- - | A comment to attach to the operation.
112+ - | Specifies a comment to attach to the operation.
103113
104114 * - ``skip``
105- - | The number of documents to skip before returning results.
115+ - | Sets the number of documents to skip before returning results.
106116
107117 * - ``limit``
108- - | The maximum number of documents to count. Must be a positive integer.
118+ - | Sets the maximum number of documents to count. Must be a positive integer.
109119
110120 * - ``maxTime``
111- - | The maximum amount of time to allow the operation to run, in milliseconds.
121+ - | Sets the maximum amount of time to allow the operation to run, in milliseconds.
112122
113123 * - ``collation``
114- - | The collation to use for the operation.
124+ - | Specifies the kind of language collation to use when sorting
125+ results. For more information, see :manual:`Collation </reference/collation/#std-label-collation>`
126+ in the {+mdb-server+} manual.
115127
116128 * - ``hint``
117- - | Gets or sets the index to scan for documents.
129+ - | Sets the index to scan for documents.
118130
119131The following example uses a ``CountOptions`` object to add a comment to the
120132``countDocuments()`` operation:
121133
122- .. code-block:: kotlin
123-
124- val options = CountOptions().comment("Retrieving count")
125- collection.countDocuments(options)
134+ .. literalinclude:: /includes/read/count.kt
135+ :start-after: start-count-options
136+ :end-before: end-count-options
137+ :language: kotlin
138+ :dedent:
126139
127140.. _kotlin-sync-estimated-count:
128141
@@ -137,10 +150,11 @@ The following example prints the estimated number of documents in a collection:
137150
138151.. io-code-block::
139152
140- .. input::
153+ .. input:: /includes/read/count.kt
154+ :start-after: start-estimated-count
155+ :end-before: end-estimated-count
141156 :language: kotlin
142-
143- print(collection.estimatedDocumentCount())
157+ :dedent:
144158
145159 .. output::
146160 :visible: false
@@ -167,18 +181,19 @@ The following table describes the options you can set to customize ``estimatedDo
167181 - Description
168182
169183 * - ``comment``
170- - | A comment to attach to the operation.
184+ - | Specifies a comment to attach to the operation.
171185
172186 * - ``maxTime``
173- - | The maximum amount of time to allow the operation to run, in milliseconds.
187+ - | Specifies the maximum amount of time to allow the operation to run, in milliseconds.
174188
175189The following example uses an ``EstimatedDocumentCountOptions`` object to add a comment to
176190the ``estimatedDocumentCount()`` operation:
177191
178- .. code-block:: kotlin
179-
180- val options = EstimatedDocumentCountOptions().comment("Retrieving count")
181- collection.estimatedDocumentCount(options)
192+ .. literalinclude:: /includes/read/count.kt
193+ :start-after: start-estimated-count-options
194+ :end-before: end-estimated-count-options
195+ :language: kotlin
196+ :dedent:
182197
183198API Documentation
184199-----------------
0 commit comments