Skip to content

Commit 6521c25

Browse files
authored
DOCSP-30505: quickstart tech review IA (#51)
1 parent 8431531 commit 6521c25

File tree

3 files changed

+55
-47
lines changed

3 files changed

+55
-47
lines changed
Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
use mongodb::{ bson::doc, Client, Collection };
2-
use bson:: Document;
2+
use bson::Document;
33

44
#[tokio::main]
55
async fn main() -> mongodb::error::Result<()> {
6-
// Replace the placeholder with your Atlas connection string
7-
let uri = "<connection string>";
8-
9-
// Create a new client and connect to the server
10-
let client = Client::with_uri_str(uri).await?;
6+
// Replace the placeholder with your Atlas connection string
7+
let uri = "<connection string>";
118

12-
// Get a handle on the "movies" collection in the "sample_mflix" database
13-
let my_coll: Collection<Document> = client.database("sample_mflix").collection("movies");
9+
// Create a new client and connect to the server
10+
let client = Client::with_uri_str(uri).await?;
1411

15-
// Find the movie "The Perils of Pauline" in the "movies" collection
16-
let my_movie = my_coll.find_one(doc! { "title": "The Perils of Pauline" }, None).await?;
12+
// Get a handle on the movies collection
13+
let my_coll: Collection<Document> = client.database("sample_mflix").collection("movies");
1714

18-
// Print the document that contains the movie found
19-
println!("{}", serde_json::to_string_pretty(&my_movie).unwrap());
20-
Ok(())
21-
}
15+
// Find a movie based on the title value
16+
let my_movie = my_coll.find_one(doc! { "title": "The Perils of Pauline" }, None).await?;
17+
18+
// Print the document
19+
println!("Found a movie:\n{:#?}", my_movie);
20+
Ok(())
21+
}
Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,21 @@
1-
use mongodb::{ bson::doc, sync::{Client} };
2-
use bson:: Document;
1+
use mongodb::{ bson::doc, sync::{ Client } };
2+
use bson::Document;
33

44
fn main() -> mongodb::error::Result<()> {
5-
// Replace the placeholder with your Atlas connection string
6-
let uri = "<connection string>";
7-
8-
// Create a new client and connect to the server
9-
let client = Client::with_uri_str(uri);
5+
// Replace the placeholder with your Atlas connection string
6+
let uri = "<connection string>";
107

11-
// Get a handle on the "movies" collection in the "sample_mflix" database
12-
let database = client?.database("sample_mflix");
13-
let my_coll = database.collection::<Document>("movies");
8+
// Create a new client and connect to the server
9+
let client = Client::with_uri_str(uri)?;
1410

15-
// Find the movie "The Perils of Pauline" in the "movies" collection
16-
let my_movie = my_coll.find_one(doc! { "title": "The Perils of Pauline" }, None)?;
11+
// Get a handle on the movies collection
12+
let database = client.database("sample_mflix");
13+
let my_coll = database.collection::<Document>("movies");
1714

18-
// Print the document that contains the movie found
19-
println!("{}", serde_json::to_string_pretty(&my_movie).unwrap());
20-
Ok(())
21-
}
22-
15+
// Find a movie based on the title value
16+
let my_movie = my_coll.find_one(doc! { "title": "The Perils of Pauline" }, None)?;
2317

18+
// Print the document
19+
println!("Found a movie:\n{:#?}", my_movie);
20+
Ok(())
21+
}

source/quick-start/connect-to-mongodb.txt

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -47,23 +47,33 @@ Connect to MongoDB
4747
command line output:
4848

4949
.. code-block:: none
50+
:copyable: false
51+
52+
Found a movie:
53+
Some(
54+
Document({
55+
"_id": ObjectId(...),
56+
"title": String(
57+
"The Perils of Pauline",
58+
),
59+
"plot": String(
60+
"Young Pauline is left a lot of money ...",
61+
),
62+
"runtime": Int32(
63+
199,
64+
),
65+
"cast": Array([
66+
String(
67+
"Pearl White",
68+
),
69+
String(
70+
"Crane Wilbur",
71+
),
72+
...
73+
]),
74+
}),
75+
)
5076

51-
{
52-
"_id": { ... },
53-
"plot": "Young Pauline is left a lot of money when her wealthy ...";
54-
"genres": [
55-
"Action"
56-
],
57-
"runtime": 199,
58-
"cast": [
59-
"Pearl White",
60-
"Crane Wilbur",
61-
"Paul Panzer",
62-
"Edward Josè"
63-
],
64-
...
65-
}
66-
6777
If you encounter an error or see no output, check whether you specified the
6878
proper connection string in the ``main.rs`` file, and that you loaded the
6979
sample data.

0 commit comments

Comments
 (0)