-
Type: Bug
-
Resolution: Fixed
-
Priority: Unknown
-
Affects Version/s: 1.2.3, 2.0.0
-
Component/s: None
-
None
The Rust driver currently follows the outdated wording of the server selection which instructs drivers not to forward secondaryPreferred read preferences to mongos. This guidance was intended for use with OP_QUERY, not OP_MSG, and results in secondaryPreferred reads always going to the primary.
repro:
#[tokio::main(flavor = "multi_thread", worker_threads = 5)] async fn main() -> Result<(), Box<dyn Error>> { let client = Client::with_uri_str("mongodb://127.0.0.1:27017").await.unwrap(); let rp = ReadPreference::SecondaryPreferred { options: Default::default() }; let doc = client.database("admin").run_command(doc! { "hello": 1 }, SelectionCriteria::ReadPreference(rp)).await?; assert!(!doc.get_bool("isWritablePrimary")?); Ok(()) }