@@ -31,6 +31,14 @@ database from the :atlas:`Atlas sample datasets </sample-data>`. To learn how to
31
31
free MongoDB Atlas cluster and load the sample datasets, see the
32
32
:atlas:`Get Started with Atlas </getting-started>` guide.
33
33
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
+
34
42
.. _kotlin-sync-accurate-count:
35
43
36
44
Retrieve an Accurate Count
@@ -40,7 +48,7 @@ Use the ``countDocuments()`` method to count the number of documents that are in
40
48
collection. To count the number of documents that match specified search
41
49
critera, pass a query filter to the ``countDocuments()`` method.
42
50
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`.
44
52
45
53
Count All Documents
46
54
~~~~~~~~~~~~~~~~~~~
@@ -50,10 +58,11 @@ with no arguments, as shown in the following example:
50
58
51
59
.. io-code-block::
52
60
53
- .. input::
61
+ .. input:: /includes/read/count.kt
62
+ :start-after: start-count-all
63
+ :end-before: end-count-all
54
64
:language: kotlin
55
-
56
- print(collection.countDocuments())
65
+ :dedent:
57
66
58
67
.. output::
59
68
:visible: false
@@ -69,10 +78,11 @@ in the ``movies`` collection that have a ``year`` field value equal to ``1930``:
69
78
70
79
.. io-code-block::
71
80
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:
76
86
77
87
.. output::
78
88
:visible: false
@@ -99,30 +109,33 @@ The following table describes the options you can set to customize ``countDocume
99
109
- Description
100
110
101
111
* - ``comment``
102
- - | A comment to attach to the operation.
112
+ - | Specifies a comment to attach to the operation.
103
113
104
114
* - ``skip``
105
- - | The number of documents to skip before returning results.
115
+ - | Sets the number of documents to skip before returning results.
106
116
107
117
* - ``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.
109
119
110
120
* - ``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.
112
122
113
123
* - ``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.
115
127
116
128
* - ``hint``
117
- - | Gets or sets the index to scan for documents.
129
+ - | Sets the index to scan for documents.
118
130
119
131
The following example uses a ``CountOptions`` object to add a comment to the
120
132
``countDocuments()`` operation:
121
133
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:
126
139
127
140
.. _kotlin-sync-estimated-count:
128
141
@@ -137,10 +150,11 @@ The following example prints the estimated number of documents in a collection:
137
150
138
151
.. io-code-block::
139
152
140
- .. input::
153
+ .. input:: /includes/read/count.kt
154
+ :start-after: start-estimated-count
155
+ :end-before: end-estimated-count
141
156
:language: kotlin
142
-
143
- print(collection.estimatedDocumentCount())
157
+ :dedent:
144
158
145
159
.. output::
146
160
:visible: false
@@ -167,18 +181,19 @@ The following table describes the options you can set to customize ``estimatedDo
167
181
- Description
168
182
169
183
* - ``comment``
170
- - | A comment to attach to the operation.
184
+ - | Specifies a comment to attach to the operation.
171
185
172
186
* - ``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.
174
188
175
189
The following example uses an ``EstimatedDocumentCountOptions`` object to add a comment to
176
190
the ``estimatedDocumentCount()`` operation:
177
191
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:
182
197
183
198
API Documentation
184
199
-----------------
0 commit comments