Skip to content

RUST-795 Update versioned api connection examples #400

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 15 additions & 20 deletions src/test/documentation_examples.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use tokio::sync::RwLockReadGuard;
use crate::{
bson::{doc, Bson},
error::Result,
options::{ClientOptions, CursorType, FindOptions, ServerApi, ServerApiVersion},
options::{ClientOptions, FindOptions, ServerApi, ServerApiVersion},
test::{TestClient, DEFAULT_URI, LOCK},
Client,
Collection,
Expand Down Expand Up @@ -1377,47 +1377,42 @@ async fn versioned_api_examples() -> Result<()> {
}

let uri = DEFAULT_URI.clone();
// Start 1. Declare an API version on a client
// Start Versioned API Example 1
let mut options = ClientOptions::parse(&uri).await?;
let server_api = ServerApi::builder().version(ServerApiVersion::V1).build();
options.server_api = Some(server_api);
let client = Client::with_options(options)?;
let cursor = client
.database("versioned_api_example")
.collection::<Document>("example")
.find(None, None)
.await?;
// End 1.
// End Versioned API Example 1

// Start 2. Strict option
// Start Versioned API Example 2
let mut options = ClientOptions::parse(&uri).await?;
let server_api = ServerApi::builder()
.version(ServerApiVersion::V1)
.strict(true)
.build();
options.server_api = Some(server_api);
let client = Client::with_options(options)?;
// End Versioned API Example 2

let find_options = FindOptions::builder()
.cursor_type(CursorType::Tailable)
// Start Versioned API Example 3
let mut options = ClientOptions::parse(&uri).await?;
let server_api = ServerApi::builder()
.version(ServerApiVersion::V1)
.strict(false)
.build();
let cursor = client
.database("versioned_api_example")
.collection::<Document>("example")
.find(None, find_options)
.await
.expect_err("should fail");
// End 2.
options.server_api = Some(server_api);
let client = Client::with_options(options)?;
// End Versioned API Example 3

// Start 3. deprecationErrors option
// Start Versioned API Example 4
let mut options = ClientOptions::parse(&uri).await?;
let server_api = ServerApi::builder()
.version(ServerApiVersion::V1)
.deprecation_errors(true)
.build();
options.server_api = Some(server_api);
let client = Client::with_options(options)?;
// End 3.
// End Versioned API Example 4

Ok(())
}
Expand Down