From 48747c405f8f8926d9891e28d1c8837d89cbdcc8 Mon Sep 17 00:00:00 2001 From: norareidy Date: Thu, 12 Dec 2024 10:48:25 -0500 Subject: [PATCH 1/2] DOCSP-44970: Modify delete usage examples --- .../code-snippets/delete-many-async.rs | 17 ++++++++++++++++- .../code-snippets/delete-many-sync.rs | 17 ++++++++++++++++- .../code-snippets/delete-one-async.rs | 10 +++++++++- .../code-snippets/delete-one-sync.rs | 10 +++++++++- source/usage-examples/deleteMany.txt | 19 ++++++++++++++----- source/usage-examples/deleteOne.txt | 17 +++++++++++++---- 6 files changed, 77 insertions(+), 13 deletions(-) diff --git a/source/includes/usage-examples/code-snippets/delete-many-async.rs b/source/includes/usage-examples/code-snippets/delete-many-async.rs index b1f5b233..d35cd92b 100644 --- a/source/includes/usage-examples/code-snippets/delete-many-async.rs +++ b/source/includes/usage-examples/code-snippets/delete-many-async.rs @@ -3,13 +3,28 @@ use mongodb::{ Client, Collection }; +use serde::{ Deserialize, Serialize }; + +#[derive(Debug, Serialize, Deserialize)] +struct Address { + street: String, + city: String, +} + +#[derive(Serialize, Deserialize, Debug)] +struct Restaurant { + name: String, + borough: String, + address: Address, +} #[tokio::main] async fn main() -> mongodb::error::Result<()> { let uri = ""; let client = Client::with_uri_str(uri).await?; - let my_coll: Collection = client + // Replace with the or type parameter + let my_coll: Collection = client .database("sample_restaurants") .collection("restaurants"); diff --git a/source/includes/usage-examples/code-snippets/delete-many-sync.rs b/source/includes/usage-examples/code-snippets/delete-many-sync.rs index 7565b1d0..f41a51ae 100644 --- a/source/includes/usage-examples/code-snippets/delete-many-sync.rs +++ b/source/includes/usage-examples/code-snippets/delete-many-sync.rs @@ -2,12 +2,27 @@ use mongodb::{ bson::{ Document, doc }, sync::{ Client, Collection } }; +use serde::{ Deserialize, Serialize }; + +#[derive(Debug, Serialize, Deserialize)] +struct Address { + street: String, + city: String, +} + +#[derive(Serialize, Deserialize, Debug)] +struct Restaurant { + name: String, + borough: String, + address: Address, +} fn main() -> mongodb::error::Result<()> { let uri = ""; let client = Client::with_uri_str(uri)?; - let my_coll: Collection = client + // Replace with the or type parameter + let my_coll: Collection = client .database("sample_restaurants") .collection("restaurants"); diff --git a/source/includes/usage-examples/code-snippets/delete-one-async.rs b/source/includes/usage-examples/code-snippets/delete-one-async.rs index 5364ef2d..a9e3b40e 100644 --- a/source/includes/usage-examples/code-snippets/delete-one-async.rs +++ b/source/includes/usage-examples/code-snippets/delete-one-async.rs @@ -3,13 +3,21 @@ use mongodb::{ Client, Collection }; +use serde::{ Deserialize, Serialize }; + +#[derive(Serialize, Deserialize, Debug)] +struct Restaurant { + name: String, + borough: String, +} #[tokio::main] async fn main() -> mongodb::error::Result<()> { let uri = ""; let client = Client::with_uri_str(uri).await?; - let my_coll: Collection = client + // Replace with the or type parameter + let my_coll: Collection = client .database("sample_restaurants") .collection("restaurants"); diff --git a/source/includes/usage-examples/code-snippets/delete-one-sync.rs b/source/includes/usage-examples/code-snippets/delete-one-sync.rs index 53a981d8..8f583e11 100644 --- a/source/includes/usage-examples/code-snippets/delete-one-sync.rs +++ b/source/includes/usage-examples/code-snippets/delete-one-sync.rs @@ -2,12 +2,20 @@ use mongodb::{ bson::{ Document, doc }, sync::{ Client, Collection } }; +use serde::{ Deserialize, Serialize }; + +#[derive(Serialize, Deserialize, Debug)] +struct Restaurant { + name: String, + borough: String, +} fn main() -> mongodb::error::Result<()> { let uri = ""; let client = Client::with_uri_str(uri)?; - let my_coll: Collection = client + // Replace with the or type parameter + let my_coll: Collection = client .database("sample_restaurants") .collection("restaurants"); diff --git a/source/usage-examples/deleteMany.txt b/source/usage-examples/deleteMany.txt index 2998636a..4dce69a1 100644 --- a/source/usage-examples/deleteMany.txt +++ b/source/usage-examples/deleteMany.txt @@ -35,13 +35,20 @@ To learn more about delete operations, see the :ref:`rust-delete-guide` guide. Example ------- -This example deletes all documents that match a query filter from the ``restaurants`` -collection in the ``sample_restaurants`` database. - -This example passes a query filter as a parameter to the ``delete_many()`` method. -The filter matches documents in which the value of the ``borough`` field is ``"Manhattan"`` +This example deletes all documents that match query filter from the ``restaurants`` +collection in the ``sample_restaurants`` database. The ``delete_many()`` method deletes +documents in which the value of the ``borough`` field is ``"Manhattan"`` and the value of the ``address.street`` field is ``"Broadway"``. +You can access the documents in the ``restaurants`` collection as instances +of the ``Document`` type or a custom data type. To specify which data type +represents the collection's data, replace the ```` type parameter on the +highlighted line with one of the following values: + +- ````: Accesses collection documents as BSON documents +- ````: Accesses collection documents as instances of the ``Restaurant`` + struct, defined at the top of the code + Select the :guilabel:`Asynchronous` or :guilabel:`Synchronous` tab to see the corresponding code for each runtime: @@ -55,6 +62,7 @@ see the corresponding code for each runtime: .. input:: /includes/usage-examples/code-snippets/delete-many-async.rs :language: rust + :emphasize-lines: 27 :dedent: .. output:: @@ -72,6 +80,7 @@ see the corresponding code for each runtime: .. input:: /includes/usage-examples/code-snippets/delete-many-sync.rs :language: rust + :emphasize-lines: 25 :dedent: .. output:: diff --git a/source/usage-examples/deleteOne.txt b/source/usage-examples/deleteOne.txt index bf502d2d..9e522e47 100644 --- a/source/usage-examples/deleteOne.txt +++ b/source/usage-examples/deleteOne.txt @@ -31,11 +31,18 @@ Example ------- This example deletes a document that matches a query filter from the ``restaurants`` -collection in the ``sample_restaurants`` database. +collection in the ``sample_restaurants`` database. The ``delete_one()`` method deletes the +first document in which the value of the ``name`` field is ``"Haagen-Dazs"`` and the +``borough`` field is ``"Brooklyn"``. -This example uses a query filter that matches documents in which the value of the -``name`` field is ``"Haagen-Dazs"`` and the ``borough`` field is ``"Brooklyn"``. MongoDB -deletes the first document that matches the query filter. +You can access the documents in the ``restaurants`` collection as instances +of the ``Document`` type or a custom data type. To specify which data type +represents the collection's data, replace the ```` type parameter on the +highlighted line with one of the following values: + +- ````: Accesses collection documents as BSON documents +- ````: Accesses collection documents as instances of the ``Restaurant`` + struct, defined at the top of the code Select the :guilabel:`Asynchronous` or :guilabel:`Synchronous` tab to see the corresponding code for each runtime: @@ -50,6 +57,7 @@ see the corresponding code for each runtime: .. input:: /includes/usage-examples/code-snippets/delete-one-async.rs :language: rust + :emphasize-lines: 20 :dedent: .. output:: @@ -66,6 +74,7 @@ see the corresponding code for each runtime: .. input:: /includes/usage-examples/code-snippets/delete-one-sync.rs :language: rust + :emphasize-lines: 18 :dedent: .. output:: From b9977a1ce8e9aed80ac66616d996403d18a89467 Mon Sep 17 00:00:00 2001 From: norareidy Date: Thu, 12 Dec 2024 16:24:22 -0500 Subject: [PATCH 2/2] SA fix --- source/usage-examples/deleteMany.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/usage-examples/deleteMany.txt b/source/usage-examples/deleteMany.txt index 4dce69a1..6faaa001 100644 --- a/source/usage-examples/deleteMany.txt +++ b/source/usage-examples/deleteMany.txt @@ -35,7 +35,7 @@ To learn more about delete operations, see the :ref:`rust-delete-guide` guide. Example ------- -This example deletes all documents that match query filter from the ``restaurants`` +This example deletes all documents that match a query filter from the ``restaurants`` collection in the ``sample_restaurants`` database. The ``delete_many()`` method deletes documents in which the value of the ``borough`` field is ``"Manhattan"`` and the value of the ``address.street`` field is ``"Broadway"``.