File tree Expand file tree Collapse file tree 2 files changed +22
-6
lines changed
source/includes/usage-examples/code-snippets Expand file tree Collapse file tree 2 files changed +22
-6
lines changed Original file line number Diff line number Diff line change @@ -14,18 +14,26 @@ async fn main() -> mongodb::error::Result<()> {
1414 let uri = "<connection string>" ;
1515
1616 let client = Client :: with_uri_str ( uri) . await ?;
17- let my_coll: Collection < Restaurant > = client
17+
18+ // Replace <T> with the <Document> or <Restaurant> type parameter
19+ let my_coll: Collection < T > = client
1820 . database ( "sample_restaurants" )
1921 . collection ( "restaurants" ) ;
2022
2123 let filter = doc ! { "name" : "Landmark Coffee Shop" } ;
22- let replacement = Restaurant {
24+ let replace_doc = doc ! {
25+ "borough" : "Brooklyn" ,
26+ "cuisine" : "Café/Coffee/Tea" ,
27+ "name" : "Harvest Moon Café" ,
28+ } ;
29+ let replace_struct = Restaurant {
2330 borough : "Brooklyn" . to_string ( ) ,
2431 cuisine : "Café/Coffee/Tea" . to_string ( ) ,
2532 name : "Harvest Moon Café" . to_string ( ) ,
2633 } ;
2734
28- let res = my_coll. replace_one ( filter, replacement) . await ?;
35+ // Replace <struct or doc> with the replace_struct or replace_doc variable
36+ let res = my_coll. replace_one ( filter, <struct or doc>) . await ?;
2937 println ! ( "Replaced documents: {}" , res. modified_count) ;
3038
3139 Ok ( ( ) )
Original file line number Diff line number Diff line change @@ -13,18 +13,26 @@ fn main() -> mongodb::error::Result<()> {
1313 let uri = "<connection string>" ;
1414
1515 let client = Client :: with_uri_str ( uri) ?;
16- let my_coll: Collection < Restaurant > = client
16+
17+ // Replace <T> with the <Document> or <Restaurant> type parameter
18+ let my_coll: Collection < T > = client
1719 . database ( "sample_restaurants" )
1820 . collection ( "restaurants" ) ;
1921
2022 let filter = doc ! { "name" : "Landmark Coffee Shop" } ;
21- let replacement = Restaurant {
23+ let replace_doc = doc ! {
24+ "borough" : "Brooklyn" ,
25+ "cuisine" : "Café/Coffee/Tea" ,
26+ "name" : "Harvest Moon Café" ,
27+ } ;
28+ let replace_struct = Restaurant {
2229 borough : "Brooklyn" . to_string ( ) ,
2330 cuisine : "Café/Coffee/Tea" . to_string ( ) ,
2431 name : "Harvest Moon Café" . to_string ( ) ,
2532 } ;
2633
27- let res = my_coll. replace_one ( filter, replacement) . run ( ) ?;
34+ // Replace <struct or doc> with the replace_struct or replace_doc variable
35+ let res = my_coll. replace_one ( filter, <struct or doc>) . run ( ) ?;
2836 println ! ( "Replaced documents: {}" , res. modified_count) ;
2937
3038 Ok ( ( ) )
You can’t perform that action at this time.
0 commit comments