1
1
use futures:: TryStreamExt ;
2
2
use mongodb:: {
3
3
bson:: doc,
4
- Client ,
5
- Collection ,
4
+ Client ,
5
+ Collection ,
6
6
results:: { InsertOneResult , InsertManyResult } ,
7
- options:: { InsertOneOptions , InsertManyOptions } ,
7
+ options:: { InsertOneOptions , InsertManyOptions } ,
8
8
} ;
9
9
use std:: env;
10
10
@@ -14,7 +14,7 @@ use serde::{ Deserialize, Serialize };
14
14
struct Book {
15
15
_id : i32 ,
16
16
title : String ,
17
- author : String ,
17
+ author : String
18
18
}
19
19
20
20
#[ tokio:: main]
@@ -32,25 +32,27 @@ async fn main() -> mongodb::error::Result<()> {
32
32
// end-insert-one
33
33
34
34
// begin-one-options
35
- let _result = my_coll. insert_one ( doc) . bypass_document_validation ( true ) . await ?;
35
+ let _result = my_coll. insert_one ( doc)
36
+ . bypass_document_validation ( true )
37
+ . await ?;
36
38
// end-one-options
37
39
38
40
// begin-insert-many
39
41
let docs = vec ! [
40
42
Book {
41
43
_id: 5 ,
42
44
title: "Cat's Cradle" . to_string( ) ,
43
- author: "Kurt Vonnegut Jr." . to_string( ) ,
45
+ author: "Kurt Vonnegut Jr." . to_string( )
44
46
} ,
45
47
Book {
46
48
_id: 6 ,
47
49
title: "In Memory of Memory" . to_string( ) ,
48
- author: "Maria Stepanova" . to_string( ) ,
50
+ author: "Maria Stepanova" . to_string( )
49
51
} ,
50
52
Book {
51
53
_id: 7 ,
52
54
title: "Pride and Prejudice" . to_string( ) ,
53
- author: "Jane Austen" . to_string( ) ,
55
+ author: "Jane Austen" . to_string( )
54
56
}
55
57
] ;
56
58
@@ -62,7 +64,9 @@ async fn main() -> mongodb::error::Result<()> {
62
64
// end-insert-many
63
65
64
66
// begin-many-options
65
- let _result = my_coll. insert_many ( docs) . comment ( Some ( "hello world" . into ( ) ) ) . await ?;
67
+ let _result = my_coll. insert_many ( docs)
68
+ . comment ( Some ( "hello world" . into ( ) ) )
69
+ . await ?;
66
70
// end-many-options
67
71
68
72
// begin-unordered
@@ -72,7 +76,7 @@ async fn main() -> mongodb::error::Result<()> {
72
76
Book { _id: 1 , title: "Blueberries for Sal" . to_string( ) , author: "" . to_string( ) } ,
73
77
Book { _id: 3 , title: "Goodnight Moon" . to_string( ) , author: "" . to_string( ) }
74
78
] ;
75
-
79
+
76
80
my_coll. insert_many ( docs) . ordered ( false ) . await ?;
77
81
// end-unordered
78
82
0 commit comments