File tree Expand file tree Collapse file tree 2 files changed +45
-7
lines changed
fundamentals/crud/write-operations
includes/fundamentals/code-snippets/crud Expand file tree Collapse file tree 2 files changed +45
-7
lines changed Original file line number Diff line number Diff line change @@ -152,8 +152,40 @@ which describes the number of documents deleted. If no documents match
152152the query filter you specified, the delete operation does
153153not remove any documents, and the value of ``deleted_count`` is ``0``.
154154
155- delete_many() Example
156- ~~~~~~~~~~~~~~~~~~~~~
155+ Delete Examples
156+ ---------------
157+
158+ This section provides code examples for the following delete operations:
159+
160+ - :ref:`delete_one() <rust-delete-one-ex>`
161+ - :ref:`delete_many() <rust-delete-many-ex>`
162+
163+ .. _rust-delete-one-ex:
164+
165+ Delete One Example
166+ ~~~~~~~~~~~~~~~~~~
167+
168+ The following example uses the ``delete_one()`` method to delete a document
169+ that has a ``item`` value of ``"placemat"``:
170+
171+ .. io-code-block::
172+
173+ .. input:: /includes/fundamentals/code-snippets/crud/delete.rs
174+ :start-after: begin-delete-one
175+ :end-before: end-delete-one
176+ :language: rust
177+ :dedent:
178+
179+ .. output::
180+ :language: console
181+ :visible: false
182+
183+ Deleted documents: 1
184+
185+ .. _rust-delete-many-ex:
186+
187+ Delete Many Example
188+ ~~~~~~~~~~~~~~~~~~~
157189
158190This example performs the following actions:
159191
@@ -163,12 +195,11 @@ This example performs the following actions:
163195- Chains the ``hint()`` method to ``delete_many()`` to use the ``_id_`` index as the hint
164196 for the delete operation
165197
166-
167198.. io-code-block::
168199
169200 .. input:: /includes/fundamentals/code-snippets/crud/delete.rs
170- :start-after: begin-delete
171- :end-before: end-delete
201+ :start-after: begin-delete-many
202+ :end-before: end-delete-many
172203 :language: rust
173204 :dedent:
174205
Original file line number Diff line number Diff line change @@ -9,7 +9,14 @@ async fn main() -> mongodb::error::Result<()> {
99
1010 let my_coll: Collection < Document > = client. database ( "db" ) . collection ( "inventory" ) ;
1111
12- // begin-delete
12+ // begin-delete-one
13+ let filter = doc ! { "item" : "placemat" } ;
14+
15+ let res = my_coll. delete_one ( filter) . await ?;
16+ println ! ( "Deleted documents: {}" , res. deleted_count) ;
17+ // end-delete-one
18+
19+ // begin-delete-many
1320 let filter = doc ! { "category" : "garden" } ;
1421 let hint = Hint :: Name ( "_id_" . to_string ( ) ) ;
1522
@@ -18,7 +25,7 @@ async fn main() -> mongodb::error::Result<()> {
1825 . hint ( hint)
1926 . await ?;
2027 println ! ( "Deleted documents: {}" , res. deleted_count) ;
21- // end-delete
28+ // end-delete-many
2229
2330 // begin-options
2431 let res = my_coll
You can’t perform that action at this time.
0 commit comments