From 05ced7d727f6d02711723871d76c7dc4dfcb8742 Mon Sep 17 00:00:00 2001 From: norareidy Date: Mon, 9 Dec 2024 11:50:25 -0500 Subject: [PATCH 1/3] DOCSP-44859: Add delete_one() example --- .../crud/write-operations/delete.txt | 41 ++++++++++++++++--- .../fundamentals/code-snippets/crud/delete.rs | 11 ++++- 2 files changed, 45 insertions(+), 7 deletions(-) diff --git a/source/fundamentals/crud/write-operations/delete.txt b/source/fundamentals/crud/write-operations/delete.txt index f8e9467e..32f060b2 100644 --- a/source/fundamentals/crud/write-operations/delete.txt +++ b/source/fundamentals/crud/write-operations/delete.txt @@ -152,8 +152,40 @@ which describes the number of documents deleted. If no documents match the query filter you specified, the delete operation does not remove any documents, and the value of ``deleted_count`` is ``0``. -delete_many() Example -~~~~~~~~~~~~~~~~~~~~~ +Delete Examples +--------------- + +This section provides code examples for the following delete operations: + +- :ref:`delete_one() ` +- :ref:`delete_many() ` + +.. _rust-delete-one-ex: + +Delete One Example +~~~~~~~~~~~~~~~~~~ + +The following example uses the ``delete_one()`` method to delete a document +that has a ``item`` value of ``"placemat"``: + +.. io-code-block:: + + .. input:: /includes/fundamentals/code-snippets/crud/delete.rs + :start-after: begin-delete-one + :end-before: end-delete-one + :language: rust + :dedent: + + .. output:: + :language: console + :visible: false + + Deleted documents: 1 + +.. _rust-delete-many-ex: + +Delete Many Example +~~~~~~~~~~~~~~~~~~~ This example performs the following actions: @@ -163,12 +195,11 @@ This example performs the following actions: - Chains the ``hint()`` method to ``delete_many()`` to use the ``_id_`` index as the hint for the delete operation - .. io-code-block:: .. input:: /includes/fundamentals/code-snippets/crud/delete.rs - :start-after: begin-delete - :end-before: end-delete + :start-after: begin-delete-many + :end-before: end-delete-many :language: rust :dedent: diff --git a/source/includes/fundamentals/code-snippets/crud/delete.rs b/source/includes/fundamentals/code-snippets/crud/delete.rs index e790f2a5..d919b78e 100644 --- a/source/includes/fundamentals/code-snippets/crud/delete.rs +++ b/source/includes/fundamentals/code-snippets/crud/delete.rs @@ -9,7 +9,14 @@ async fn main() -> mongodb::error::Result<()> { let my_coll: Collection = client.database("db").collection("inventory"); - // begin-delete + // begin-delete-one + let filter = doc! { "item": "placemat" }; + + let res = my_coll.delete_one(filter).await?; + println!("Deleted documents: {}", res.deleted_count); + // end-delete-one + + // begin-delete-many let filter = doc! { "category": "garden" }; let hint = Hint::Name("_id_".to_string()); @@ -18,7 +25,7 @@ async fn main() -> mongodb::error::Result<()> { .hint(hint) .await?; println!("Deleted documents: {}", res.deleted_count); - // end-delete + // end-delete-many // begin-options let res = my_coll From 3d0e5ff234e7ebf2079c613a1f50f3fb9c3d7bad Mon Sep 17 00:00:00 2001 From: norareidy Date: Mon, 9 Dec 2024 11:57:47 -0500 Subject: [PATCH 2/3] edit overview --- source/fundamentals/crud/write-operations/delete.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/source/fundamentals/crud/write-operations/delete.txt b/source/fundamentals/crud/write-operations/delete.txt index 32f060b2..e25b4aa1 100644 --- a/source/fundamentals/crud/write-operations/delete.txt +++ b/source/fundamentals/crud/write-operations/delete.txt @@ -31,6 +31,9 @@ This guide includes the following sections: - :ref:`Delete Operations ` describes how to use the driver to execute delete operations +- :ref:`Delete Examples ` provides code examples + for the delete operations + - :ref:`Additional Information ` provides links to resources and API documentation for types and methods mentioned in this guide From 3899efe5284130cacb414f20c5eff9dc351d87e5 Mon Sep 17 00:00:00 2001 From: norareidy Date: Mon, 9 Dec 2024 13:18:20 -0500 Subject: [PATCH 3/3] MW feedback --- source/fundamentals/crud/write-operations/delete.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/fundamentals/crud/write-operations/delete.txt b/source/fundamentals/crud/write-operations/delete.txt index e25b4aa1..62c75f46 100644 --- a/source/fundamentals/crud/write-operations/delete.txt +++ b/source/fundamentals/crud/write-operations/delete.txt @@ -169,7 +169,7 @@ Delete One Example ~~~~~~~~~~~~~~~~~~ The following example uses the ``delete_one()`` method to delete a document -that has a ``item`` value of ``"placemat"``: +that has an ``item`` value of ``"placemat"``: .. io-code-block::