Skip to content

Commit 8649eb2

Browse files
committed
DOCSP-44970: Modify delete usage examples (#157)
(cherry picked from commit 36cdfab)
1 parent 8c644be commit 8649eb2

File tree

6 files changed

+76
-12
lines changed

6 files changed

+76
-12
lines changed

source/includes/usage-examples/code-snippets/delete-many-async.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,28 @@ use mongodb::{
33
Client,
44
Collection
55
};
6+
use serde::{ Deserialize, Serialize };
7+
8+
#[derive(Debug, Serialize, Deserialize)]
9+
struct Address {
10+
street: String,
11+
city: String,
12+
}
13+
14+
#[derive(Serialize, Deserialize, Debug)]
15+
struct Restaurant {
16+
name: String,
17+
borough: String,
18+
address: Address,
19+
}
620

721
#[tokio::main]
822
async fn main() -> mongodb::error::Result<()> {
923
let uri = "<connection string>";
1024
let client = Client::with_uri_str(uri).await?;
1125

12-
let my_coll: Collection<Document> = client
26+
// Replace <T> with the <Document> or <Restaurant> type parameter
27+
let my_coll: Collection<T> = client
1328
.database("sample_restaurants")
1429
.collection("restaurants");
1530

source/includes/usage-examples/code-snippets/delete-many-sync.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,27 @@ use mongodb::{
22
bson::{ Document, doc },
33
sync::{ Client, Collection }
44
};
5+
use serde::{ Deserialize, Serialize };
6+
7+
#[derive(Debug, Serialize, Deserialize)]
8+
struct Address {
9+
street: String,
10+
city: String,
11+
}
12+
13+
#[derive(Serialize, Deserialize, Debug)]
14+
struct Restaurant {
15+
name: String,
16+
borough: String,
17+
address: Address,
18+
}
519

620
fn main() -> mongodb::error::Result<()> {
721
let uri = "<connection string>";
822
let client = Client::with_uri_str(uri)?;
923

10-
let my_coll: Collection<Document> = client
24+
// Replace <T> with the <Document> or <Restaurant> type parameter
25+
let my_coll: Collection<T> = client
1126
.database("sample_restaurants")
1227
.collection("restaurants");
1328

source/includes/usage-examples/code-snippets/delete-one-async.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,21 @@ use mongodb::{
33
Client,
44
Collection
55
};
6+
use serde::{ Deserialize, Serialize };
7+
8+
#[derive(Serialize, Deserialize, Debug)]
9+
struct Restaurant {
10+
name: String,
11+
borough: String,
12+
}
613

714
#[tokio::main]
815
async fn main() -> mongodb::error::Result<()> {
916
let uri = "<connection string>";
1017
let client = Client::with_uri_str(uri).await?;
1118

12-
let my_coll: Collection<Document> = client
19+
// Replace <T> with the <Document> or <Restaurant> type parameter
20+
let my_coll: Collection<T> = client
1321
.database("sample_restaurants")
1422
.collection("restaurants");
1523

source/includes/usage-examples/code-snippets/delete-one-sync.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,20 @@ use mongodb::{
22
bson::{ Document, doc },
33
sync::{ Client, Collection }
44
};
5+
use serde::{ Deserialize, Serialize };
6+
7+
#[derive(Serialize, Deserialize, Debug)]
8+
struct Restaurant {
9+
name: String,
10+
borough: String,
11+
}
512

613
fn main() -> mongodb::error::Result<()> {
714
let uri = "<connection string>";
815
let client = Client::with_uri_str(uri)?;
916

10-
let my_coll: Collection<Document> = client
17+
// Replace <T> with the <Document> or <Restaurant> type parameter
18+
let my_coll: Collection<T> = client
1119
.database("sample_restaurants")
1220
.collection("restaurants");
1321

source/usage-examples/deleteMany.txt

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,19 @@ Example
3636
-------
3737

3838
This example deletes all documents that match a query filter from the ``restaurants``
39-
collection in the ``sample_restaurants`` database.
40-
41-
This example passes a query filter as a parameter to the ``delete_many()`` method.
42-
The filter matches documents in which the value of the ``borough`` field is ``"Manhattan"``
39+
collection in the ``sample_restaurants`` database. The ``delete_many()`` method deletes
40+
documents in which the value of the ``borough`` field is ``"Manhattan"``
4341
and the value of the ``address.street`` field is ``"Broadway"``.
4442

43+
You can access the documents in the ``restaurants`` collection as instances
44+
of the ``Document`` type or a custom data type. To specify which data type
45+
represents the collection's data, replace the ``<T>`` type parameter on the
46+
highlighted line with one of the following values:
47+
48+
- ``<Document>``: Accesses collection documents as BSON documents
49+
- ``<Restaurant>``: Accesses collection documents as instances of the ``Restaurant``
50+
struct, defined at the top of the code
51+
4552
Select the :guilabel:`Asynchronous` or :guilabel:`Synchronous` tab to
4653
see the corresponding code for each runtime:
4754

@@ -55,6 +62,7 @@ see the corresponding code for each runtime:
5562

5663
.. input:: /includes/usage-examples/code-snippets/delete-many-async.rs
5764
:language: rust
65+
:emphasize-lines: 27
5866
:dedent:
5967

6068
.. output::
@@ -72,6 +80,7 @@ see the corresponding code for each runtime:
7280

7381
.. input:: /includes/usage-examples/code-snippets/delete-many-sync.rs
7482
:language: rust
83+
:emphasize-lines: 25
7584
:dedent:
7685

7786
.. output::

source/usage-examples/deleteOne.txt

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,18 @@ Example
3131
-------
3232

3333
This example deletes a document that matches a query filter from the ``restaurants``
34-
collection in the ``sample_restaurants`` database.
34+
collection in the ``sample_restaurants`` database. The ``delete_one()`` method deletes the
35+
first document in which the value of the ``name`` field is ``"Haagen-Dazs"`` and the
36+
``borough`` field is ``"Brooklyn"``.
3537

36-
This example uses a query filter that matches documents in which the value of the
37-
``name`` field is ``"Haagen-Dazs"`` and the ``borough`` field is ``"Brooklyn"``. MongoDB
38-
deletes the first document that matches the query filter.
38+
You can access the documents in the ``restaurants`` collection as instances
39+
of the ``Document`` type or a custom data type. To specify which data type
40+
represents the collection's data, replace the ``<T>`` type parameter on the
41+
highlighted line with one of the following values:
42+
43+
- ``<Document>``: Accesses collection documents as BSON documents
44+
- ``<Restaurant>``: Accesses collection documents as instances of the ``Restaurant``
45+
struct, defined at the top of the code
3946

4047
Select the :guilabel:`Asynchronous` or :guilabel:`Synchronous` tab to
4148
see the corresponding code for each runtime:
@@ -50,6 +57,7 @@ see the corresponding code for each runtime:
5057

5158
.. input:: /includes/usage-examples/code-snippets/delete-one-async.rs
5259
:language: rust
60+
:emphasize-lines: 20
5361
:dedent:
5462

5563
.. output::
@@ -66,6 +74,7 @@ see the corresponding code for each runtime:
6674

6775
.. input:: /includes/usage-examples/code-snippets/delete-one-sync.rs
6876
:language: rust
77+
:emphasize-lines: 18
6978
:dedent:
7079

7180
.. output::

0 commit comments

Comments
 (0)