1
1
use bson:: Document ;
2
- use mongodb:: { bson:: doc, Client , Collection , options:: UpdateOptions } ;
2
+ use mongodb:: { bson:: doc, options:: UpdateOptions , Client , Collection } ;
3
3
use std:: env;
4
4
5
5
#[ tokio:: main]
@@ -10,30 +10,31 @@ async fn main() -> mongodb::error::Result<()> {
10
10
let my_coll: Collection < Document > = client. database ( "db" ) . collection ( "employees" ) ;
11
11
12
12
// begin-update
13
- let update_doc =
14
- doc ! {
13
+ let update_doc = doc ! {
15
14
"$set" : doc!{ "department" : "Business Operations" ,
16
15
"role" : "Analytics Specialist" } ,
17
16
"$inc" : doc!{ "bonus" : 500 }
18
17
} ;
19
18
20
- let res = my_coll. update_many ( doc ! { "department" : "Marketing" } , update_doc, None ) . await ?;
19
+ let res = my_coll
20
+ . update_many ( doc ! { "department" : "Marketing" } , update_doc, None )
21
+ . await ?;
21
22
println ! ( "Modified {} document(s)" , res. modified_count) ;
22
23
// end-update
23
24
24
25
// begin-replace
25
- let replace_doc =
26
- doc ! {
26
+ let replace_doc = doc ! {
27
27
"name" : "Susan Lee" ,
28
28
"role" : "Lead Consultant" ,
29
29
"team_members" : vec! [ "Jill Gillison" ]
30
30
} ;
31
31
32
- let res = my_coll. replace_one ( doc ! { "_id" : 4501 } , replace_doc, None ) . await ?;
32
+ let res = my_coll
33
+ . replace_one ( doc ! { "_id" : 4501 } , replace_doc, None )
34
+ . await ?;
33
35
println ! (
34
36
"Matched {} document(s)\n Modified {} document(s)" ,
35
- res. matched_count,
36
- res. modified_count
37
+ res. matched_count, res. modified_count
37
38
) ;
38
39
// end-replace
39
40
0 commit comments