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,27 +32,25 @@ 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)
36
- . bypass_document_validation ( true )
37
- . await ?;
35
+ let _result = my_coll. insert_one ( doc) . bypass_document_validation ( true ) . await ?;
38
36
// end-one-options
39
37
40
38
// begin-insert-many
41
39
let docs = vec ! [
42
40
Book {
43
41
_id: 5 ,
44
42
title: "Cat's Cradle" . to_string( ) ,
45
- author: "Kurt Vonnegut Jr." . to_string( )
43
+ author: "Kurt Vonnegut Jr." . to_string( ) ,
46
44
} ,
47
45
Book {
48
46
_id: 6 ,
49
47
title: "In Memory of Memory" . to_string( ) ,
50
- author: "Maria Stepanova" . to_string( )
48
+ author: "Maria Stepanova" . to_string( ) ,
51
49
} ,
52
50
Book {
53
51
_id: 7 ,
54
52
title: "Pride and Prejudice" . to_string( ) ,
55
- author: "Jane Austen" . to_string( )
53
+ author: "Jane Austen" . to_string( ) ,
56
54
}
57
55
] ;
58
56
@@ -64,19 +62,17 @@ async fn main() -> mongodb::error::Result<()> {
64
62
// end-insert-many
65
63
66
64
// begin-many-options
67
- let _result = my_coll. insert_many ( docs)
68
- . comment ( Some ( "hello world" . into ( ) ) )
69
- . await ?;
65
+ let _result = my_coll. insert_many ( docs) . comment ( Some ( "hello world" . into ( ) ) ) . await ?;
70
66
// end-many-options
71
67
72
68
// begin-unordered
73
69
let docs = vec ! [
74
70
Book { _id: 1 , title: "Where the Wild Things Are" . to_string( ) , author: "" . to_string( ) } ,
75
71
Book { _id: 2 , title: "The Very Hungry Caterpillar" . to_string( ) , author: "" . to_string( ) } ,
76
- Book { _id: 4 , title: "Blueberries for Sal" . to_string( ) , author: "" . to_string( ) } ,
72
+ Book { _id: 1 , title: "Blueberries for Sal" . to_string( ) , author: "" . to_string( ) } ,
77
73
Book { _id: 3 , title: "Goodnight Moon" . to_string( ) , author: "" . to_string( ) }
78
74
] ;
79
-
75
+
80
76
my_coll. insert_many ( docs) . ordered ( false ) . await ?;
81
77
// end-unordered
82
78
0 commit comments