1
Rust 애플리케이션 만들기
rust_quickstart/src 프로젝트 디렉토리에서 main.rs 파일을 엽니다. 이 파일에서 애플리케이션 작성을 시작할 수 있습니다.
다음 코드를 복사하여 main.rs 파일에 붙여넣습니다.
use mongodb::{  	bson::{Document, doc}, 	Client, 	Collection  }; async fn main() -> mongodb::error::Result<()> {     // Replace the placeholder with your Atlas connection string     let uri = "<connection string>";     // Create a new client and connect to the server     let client = Client::with_uri_str(uri).await?;     // Get a handle on the movies collection     let database = client.database("sample_mflix");     let my_coll: Collection<Document> = database.collection("movies");     // Find a movie based on the title value     let my_movie = my_coll.find_one(doc! { "title": "The Perils of Pauline" }).await?;     // Print the document     println!("Found a movie:\n{:#?}", my_movie);     Ok(()) } 
use mongodb::{  	bson::{Document, doc}, 	sync::{Client, Collection}  }; fn main() -> mongodb::error::Result<()> {     // Replace the placeholder with your Atlas connection string     let uri = "<connection string>";     // Create a new client and connect to the server     let client = Client::with_uri_str(uri)?;     // Get a handle on the movies collection     let database = client.database("sample_mflix");     let my_coll: Collection<Document> = database.collection("movies");     // Find a movie based on the title value     let my_movie = my_coll         .find_one(doc! { "title": "The Perils of Pauline" })         .run()?;     // Print the document     println!("Found a movie:\n{:#?}", my_movie);     Ok(()) } 
2
연결 문자열 할당
<connection string> 자리 표시자를 string 이 가이드 의 연결 만들기 단계에서 복사한 연결  string 로 바꿉니다.
3
Rust 애플리케이션 실행
shell에서 다음 명령을 실행하여 이 애플리케이션을 컴파일하고 실행합니다.
cargo run 
명령줄 출력에는 검색된 영화 문서에 대한 세부 정보가 포함됩니다.
Found a movie: Some(     Document({         "_id": ObjectId(...),         "title": String(             "The Perils of Pauline",         ),         "plot": String(             "Young Pauline is left a lot of money ...",         ),         "runtime": Int32(             199,         ),         "cast": Array([             String(                 "Pearl White",             ),             String(                 "Crane Wilbur",             ),             ...         ]),     }), ) 
오류가 발생하거나 출력이 표시되지 않는 경우 main.rs 파일에 적절한 연결 문자열을 지정했는지, 그리고 샘플 데이터를 로드했는지 확인합니다.
이 단계를 완료한 후에는 드라이버를 사용하여 MongoDB deployment에 연결하고, 샘플 데이터에 대해 쿼리를 실행하고, 결과를 출력하는 등 정상적으로 작동하는 애플리케이션을 갖게 될 것입니다.
참고
이 단계에서 문제가 실행 하면 MongoDB Stack Overflow 태그를 지정하다 또는 일반 기술 지원 위한 MongoDB Reddit Community 를 참조하거나 연결 문제 해결 가이드 참조하세요.