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..6faaa001 100644 --- a/source/usage-examples/deleteMany.txt +++ b/source/usage-examples/deleteMany.txt @@ -36,12 +36,19 @@ 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"`` +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::