Skip to content

Commit 63c29b5

Browse files
committed
DOCSP-44858: fix ordered write code
1 parent 4ddd435 commit 63c29b5

File tree

1 file changed

+11
-15
lines changed
  • source/includes/fundamentals/code-snippets/crud

1 file changed

+11
-15
lines changed

source/includes/fundamentals/code-snippets/crud/insert.rs

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
use futures::TryStreamExt;
22
use mongodb::{
33
bson::doc,
4-
Client,
5-
Collection,
4+
Client,
5+
Collection,
66
results::{ InsertOneResult, InsertManyResult },
7-
options::{ InsertOneOptions, InsertManyOptions },
7+
options::{ InsertOneOptions, InsertManyOptions },
88
};
99
use std::env;
1010

@@ -14,7 +14,7 @@ use serde::{ Deserialize, Serialize };
1414
struct Book {
1515
_id: i32,
1616
title: String,
17-
author: String
17+
author: String,
1818
}
1919

2020
#[tokio::main]
@@ -32,27 +32,25 @@ async fn main() -> mongodb::error::Result<()> {
3232
// end-insert-one
3333

3434
// 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?;
3836
// end-one-options
3937

4038
// begin-insert-many
4139
let docs = vec![
4240
Book {
4341
_id: 5,
4442
title: "Cat's Cradle".to_string(),
45-
author: "Kurt Vonnegut Jr.".to_string()
43+
author: "Kurt Vonnegut Jr.".to_string(),
4644
},
4745
Book {
4846
_id: 6,
4947
title: "In Memory of Memory".to_string(),
50-
author: "Maria Stepanova".to_string()
48+
author: "Maria Stepanova".to_string(),
5149
},
5250
Book {
5351
_id: 7,
5452
title: "Pride and Prejudice".to_string(),
55-
author: "Jane Austen".to_string()
53+
author: "Jane Austen".to_string(),
5654
}
5755
];
5856

@@ -64,19 +62,17 @@ async fn main() -> mongodb::error::Result<()> {
6462
// end-insert-many
6563

6664
// 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?;
7066
// end-many-options
7167

7268
// begin-unordered
7369
let docs = vec![
7470
Book { _id: 1, title: "Where the Wild Things Are".to_string(), author: "".to_string() },
7571
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() },
7773
Book { _id: 3, title: "Goodnight Moon".to_string(), author: "".to_string() }
7874
];
79-
75+
8076
my_coll.insert_many(docs).ordered(false).await?;
8177
// end-unordered
8278

0 commit comments

Comments
 (0)