Skip to content

Commit 781da09

Browse files
RUST-478 Add connection snippet examples (#224)
1 parent 9fa1655 commit 781da09

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

tests/connection_snippets.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#![allow(dead_code)]
2+
#![allow(unused_imports)]
3+
#![allow(unused_variables)]
4+
5+
extern crate mongodb;
6+
7+
#[cfg(feature = "tokio-runtime")]
8+
// CONNECTION EXAMPLE STARTS HERE
9+
#[tokio::main]
10+
async fn main() -> mongodb::error::Result<()> {
11+
use mongodb::{options::ClientOptions, Client};
12+
let client_options = ClientOptions::parse(
13+
"mongodb+srv://<username>:<password>@<cluster-url>/<dbname>?w=majority",
14+
)
15+
.await?;
16+
let client = Client::with_options(client_options)?;
17+
let database = client.database("test");
18+
Ok(())
19+
}
20+
// CONNECTION EXAMPLE ENDS HERE

0 commit comments

Comments
 (0)