@@ -24,8 +24,8 @@ In this guide, you can learn how to use the {+driver-short+} to remove
24
24
documents from a MongoDB collection by performing **delete operations**.
25
25
26
26
A delete operation removes one or more documents from a MongoDB collection.
27
- You can perform a delete operation by using the ``delete_one ()`` or
28
- ``delete_many ()`` methods.
27
+ You can perform a delete operation by using the ``deleteOne ()`` or
28
+ ``deleteMany ()`` methods.
29
29
30
30
.. TODO .. tip:: Interactive Lab
31
31
@@ -54,6 +54,7 @@ The documents in this collection are modeled by the following {+language+} data
54
54
:end-before: end-data-class
55
55
:language: kotlin
56
56
:copyable:
57
+ :dedent:
57
58
58
59
Delete Operations
59
60
-----------------
@@ -80,6 +81,7 @@ document in which the value of the ``name`` field is ``"Happy Garden"``:
80
81
:end-before: end-delete-one
81
82
:language: kotlin
82
83
:copyable:
84
+ :dedent:
83
85
84
86
Delete Multiple Documents
85
87
~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -93,6 +95,7 @@ value of the ``name`` field is ``"Starbucks"``:
93
95
:end-before: end-delete-many
94
96
:language: kotlin
95
97
:copyable:
98
+ :dedent:
96
99
97
100
Customize the Delete Operation
98
101
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -141,17 +144,18 @@ configure a ``DeleteOptions`` instance:
141
144
fields </reference/command/delete/#command-fields>` guide in the
142
145
{+mdb-server+} manual for more information.
143
146
144
- The following code uses the ``deleteMany ()`` method to delete all
145
- documents in the ``restaurants`` collection in which the value of the
146
- ``name `` field includes the string ``"Red"``. The example also uses the
147
- ``comment()`` method to add a comment to the operation and passes the
148
- resulting ``DeleteOptions`` instance to the ``deleteMany()`` method:
147
+ The following code creates options and uses the ``comment ()`` method to
148
+ add a comment to the delete operation. Then, the example uses the
149
+ ``deleteMany() `` method to delete all documents in the ``restaurants``
150
+ collection in which the value of the ``name`` field includes the string
151
+ ``"Red"``.
149
152
150
153
.. literalinclude:: /includes/write/delete.kt
151
154
:start-after: start-delete-options
152
155
:end-before: end-delete-options
153
156
:language: kotlin
154
157
:copyable:
158
+ :dedent:
155
159
156
160
.. tip::
157
161
@@ -170,6 +174,9 @@ a ``DeleteResult`` instance:
170
174
- ``wasAcknowledged()``, which returns ``true`` if the server
171
175
acknowledges the result
172
176
177
+ If the query filter does not match any documents, the driver doesn't delete any
178
+ documents and the value of ``deletedCount`` is ``0``.
179
+
173
180
.. note::
174
181
175
182
If the ``wasAcknowledged()`` method returns ``false``, trying to
@@ -178,17 +185,14 @@ a ``DeleteResult`` instance:
178
185
determine these values if the server does not acknowledge the write
179
186
operation.
180
187
181
- If the query filter does not match any documents, the driver doesn't delete any
182
- documents and ``deletedCount`` is ``0``.
183
-
184
188
API Documentation
185
189
~~~~~~~~~~~~~~~~~
186
190
187
191
To learn more about any of the methods or types discussed in this
188
192
guide, see the following API Documentation:
189
193
190
194
- `deleteOne() <{+api+}/mongodb-driver-kotlin-sync/com.mongodb.kotlin.client/-mongo-collection/delete-one.html>`__
191
- - `deleteOne () <{+api+}/mongodb-driver-kotlin-sync/com.mongodb.kotlin.client/-mongo-collection/delete-many.html>`__
195
+ - `deleteMany () <{+api+}/mongodb-driver-kotlin-sync/com.mongodb.kotlin.client/-mongo-collection/delete-many.html>`__
192
196
- `DeleteResult <{+core-api+}/com/mongodb/client/result/DeleteResult.html>`__
193
197
194
198
.. .. _kotlin-sync-delete-instruqt-lab:
0 commit comments