Skip to content

Commit 4c118be

Browse files
committed
DOCSP-30515: update many usage example (#81)
(cherry picked from commit d0bcf80)
1 parent ea585c9 commit 4c118be

19 files changed

+175
-136
lines changed
Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,12 @@
1-
use mongodb::{
2-
bson::doc,
3-
Client,
4-
Collection
5-
};
6-
use serde::{ Deserialize, Serialize };
7-
8-
#[derive(Serialize, Deserialize, Debug)]
9-
struct Restaurant {
10-
address: Address,
11-
borough: String,
12-
}
13-
14-
#[derive(Serialize, Deserialize, Debug)]
15-
struct Address {
16-
street: String,
17-
}
1+
use mongodb::{ bson::doc, Client, Collection };
2+
use bson::Document;
183

194
#[tokio::main]
205
async fn main() -> mongodb::error::Result<()> {
216
let uri = "<connection string>";
227
let client = Client::with_uri_str(uri).await?;
238

24-
let my_coll: Collection<Restaurant> = client
9+
let my_coll: Collection<Document> = client
2510
.database("sample_restaurants")
2611
.collection("restaurants");
2712

@@ -37,4 +22,4 @@ async fn main() -> mongodb::error::Result<()> {
3722
println!("Deleted documents: {}", result.deleted_count);
3823

3924
Ok(())
40-
}
25+
}
Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,11 @@
1-
use mongodb::{
2-
bson::doc,
3-
sync::{Client, Collection}
4-
};
5-
use serde::{ Deserialize, Serialize };
6-
7-
#[derive(Serialize, Deserialize, Debug)]
8-
struct Restaurant {
9-
address: Address,
10-
borough: String,
11-
}
12-
13-
#[derive(Serialize, Deserialize, Debug)]
14-
struct Address {
15-
street: String,
16-
}
1+
use mongodb::{ bson::doc, sync::{ Client, Collection } };
2+
use bson::Document;
173

184
fn main() -> mongodb::error::Result<()> {
195
let uri = "<connection string>";
206
let client = Client::with_uri_str(uri)?;
217

22-
let my_coll: Collection<Restaurant> = client
8+
let my_coll: Collection<Document> = client
239
.database("sample_restaurants")
2410
.collection("restaurants");
2511

@@ -35,4 +21,4 @@ fn main() -> mongodb::error::Result<()> {
3521
println!("Deleted documents: {}", result.deleted_count);
3622

3723
Ok(())
38-
}
24+
}
Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,12 @@
1-
use mongodb::{
2-
bson::doc,
3-
Client,
4-
Collection
5-
};
6-
use serde::{ Deserialize, Serialize };
7-
8-
#[derive(Serialize, Deserialize, Debug)]
9-
struct Restaurant {
10-
name: String,
11-
borough: String,
12-
}
1+
use mongodb::{ bson::doc, Client, Collection };
2+
use bson::Document;
133

144
#[tokio::main]
155
async fn main() -> mongodb::error::Result<()> {
166
let uri = "<connection string>";
177
let client = Client::with_uri_str(uri).await?;
188

19-
let my_coll: Collection<Restaurant> = client
9+
let my_coll: Collection<Document> = client
2010
.database("sample_restaurants")
2111
.collection("restaurants");
2212

@@ -30,7 +20,6 @@ async fn main() -> mongodb::error::Result<()> {
3020
let result = my_coll.delete_one(filter, None).await?;
3121

3222
println!("Deleted documents: {}", result.deleted_count);
33-
23+
3424
Ok(())
3525
}
36-
Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,11 @@
1-
use mongodb::{
2-
bson::doc,
3-
sync::{Client, Collection}
4-
};
5-
use serde::{ Deserialize, Serialize };
6-
7-
#[derive(Serialize, Deserialize, Debug)]
8-
struct Restaurant {
9-
name: String,
10-
borough: String,
11-
}
1+
use mongodb::{ bson::doc, sync::{ Client, Collection } };
2+
use bson::Document;
123

134
fn main() -> mongodb::error::Result<()> {
145
let uri = "<connection string>";
156
let client = Client::with_uri_str(uri)?;
167

17-
let my_coll: Collection<Restaurant> = client
8+
let my_coll: Collection<Document> = client
189
.database("sample_restaurants")
1910
.collection("restaurants");
2011

@@ -28,6 +19,6 @@ fn main() -> mongodb::error::Result<()> {
2819
let result = my_coll.delete_one(filter, None)?;
2920

3021
println!("Deleted documents: {}", result.deleted_count);
31-
22+
3223
Ok(())
33-
}
24+
}

source/includes/usage-examples/code-snippets/replace-async.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,7 @@ async fn main() -> mongodb::error::Result<()> {
2626
};
2727

2828
let res = my_coll.replace_one(filter, replacement, None).await?;
29-
println!(
30-
"Matched documents: {}\nReplaced documents: {}",
31-
res.matched_count,
32-
res.modified_count
33-
);
29+
println!("Replaced documents: {}", res.modified_count);
3430

3531
Ok(())
3632
}

source/includes/usage-examples/code-snippets/replace-sync.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,7 @@ fn main() -> mongodb::error::Result<()> {
2525
};
2626

2727
let res = my_coll.replace_one(filter, replacement, None)?;
28-
println!(
29-
"Matched documents: {}\nReplaced documents: {}",
30-
res.matched_count,
31-
res.modified_count
32-
);
28+
println!("Replaced documents: {}", res.modified_count);
3329

3430
Ok(())
3531
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
use std::env;
2+
use mongodb::{ bson::doc, Client, Collection };
3+
use bson::Document;
4+
5+
#[tokio::main]
6+
async fn main() -> mongodb::error::Result<()> {
7+
let uri = "<connection string>";
8+
9+
let client = Client::with_uri_str(uri).await?;
10+
let my_coll: Collection<Document> = client
11+
.database("sample_restaurants")
12+
.collection("restaurants");
13+
14+
let filter =
15+
doc! {
16+
"address.street": "Sullivan Street",
17+
"borough": "Manhattan"
18+
};
19+
let update = doc! { "$set": doc! { "near_me": true } };
20+
21+
let res = my_coll.update_many(filter, update, None).await?;
22+
println!("Updated documents: {}", res.modified_count);
23+
24+
Ok(())
25+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
use std::env;
2+
use mongodb::{ bson::doc, sync::{ Client, Collection } };
3+
use bson::Document;
4+
5+
fn main() -> mongodb::error::Result<()> {
6+
let uri = "<connection string>";
7+
8+
let client = Client::with_uri_str(uri)?;
9+
let my_coll: Collection<Document> = client
10+
.database("sample_restaurants")
11+
.collection("restaurants");
12+
13+
let filter =
14+
doc! {
15+
"address.street": "Sullivan Street",
16+
"borough": "Manhattan"
17+
};
18+
let update = doc! { "$set": doc! { "near_me": true } };
19+
20+
let res = my_coll.update_many(filter, update, None)?;
21+
println!("Updated documents: {}", res.modified_count);
22+
23+
Ok(())
24+
}
Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,21 @@
11
use std::env;
22
use mongodb::{ bson::doc, Client, Collection };
3-
use serde::{ Deserialize, Serialize };
4-
5-
#[derive(Serialize, Deserialize, Debug)]
6-
struct Restaurant {
7-
borough: String,
8-
cuisine: String,
9-
name: String,
10-
}
3+
use bson::Document;
114

125
#[tokio::main]
136
async fn main() -> mongodb::error::Result<()> {
147
let uri = "<connection string>";
158

169
let client = Client::with_uri_str(uri).await?;
17-
let my_coll: Collection<Restaurant> = client
10+
let my_coll: Collection<Document> = client
1811
.database("sample_restaurants")
1912
.collection("restaurants");
2013

2114
let filter = doc! { "name": "Spice Market" };
2215
let update = doc! { "$set": doc! {"price": "$$$"} };
2316

2417
let res = my_coll.update_one(filter, update, None).await?;
25-
println!(
26-
"Matched documents: {}\nUpdated documents: {}",
27-
res.matched_count,
28-
res.modified_count
29-
);
18+
println!("Updated documents: {}", res.modified_count);
3019

3120
Ok(())
3221
}
Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,20 @@
11
use std::env;
22
use mongodb::{ bson::doc, sync::{ Client, Collection } };
3-
use serde::{ Deserialize, Serialize };
4-
5-
#[derive(Serialize, Deserialize, Debug)]
6-
struct Restaurant {
7-
borough: String,
8-
cuisine: String,
9-
name: String,
10-
}
3+
use bson::Document;
114

125
fn main() -> mongodb::error::Result<()> {
136
let uri = "<connection string>";
147

158
let client = Client::with_uri_str(uri)?;
16-
let my_coll: Collection<Restaurant> = client
9+
let my_coll: Collection<Document> = client
1710
.database("sample_restaurants")
1811
.collection("restaurants");
1912

2013
let filter = doc! { "name": "Spice Market" };
2114
let update = doc! { "$set": doc! {"price": "$$$"} };
2215

2316
let res = my_coll.update_one(filter, update, None)?;
24-
println!(
25-
"Matched documents: {}\nUpdated documents: {}",
26-
res.matched_count,
27-
res.modified_count
28-
);
17+
println!("Updated documents: {}", res.modified_count);
2918

3019
Ok(())
3120
}

0 commit comments

Comments
 (0)