-
Type: Task
-
Resolution: Duplicate
-
Priority: Major - P3
-
None
-
Affects Version/s: None
-
Component/s: None
-
Labels:
I have a problem connecting to my mongo database which is hosted on Atlas using this crate. I am trying to switch from the old rust client which is a using mongo-c-driver and works well in order to reduce the dependency in C libs.
I have created 2 clusters to be able to reproduce the issue in an non-production environment. The first cluster is an M10 replicaset in which I can reproduce the issue. The 2nd cluster is M0 sandbox which works well with this crate.
I am using the following code
main.rs:
Unable to find source-code formatter for language: rust. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
use bson::{doc, bson}; use mongodb::{Client, options::ClientOptions, options::FindOptions}; use serde::{Deserialize, Serialize}; #[derive(Serialize, Deserialize, Debug)] struct Book { pub title: String, // pub author: String, } struct MongoCfg<'a> { pub database: &'a str, pub collection: &'a str, pub url: &'a str, pub protocol: &'a str, } fn main() { let test_cases = vec![ MongoCfg { database: "sample_airbnb", collection: "books", url: "test-cluster-02-tnjmp.mongodb.net", protocol: "mongodb+srv", }, MongoCfg { database: "sample_airbnb", collection: "books", url: "test-cluster-01-tnjmp.mongodb.net", protocol: "mongodb+srv", }, MongoCfg { database: "sample_airbnb", collection: "books", url: "test-cluster-01-shard-00-00-tnjmp.mongodb.net:27017,test-cluster-01-shard-00-01-tnjmp.mongodb.net:27017,test-cluster-01-shard-00-02-tnjmp.mongodb.net:27017/test?replicaSet=test-cluster-01-shard-0&ssl=true&authSource=admin", protocol: "mongodb", }, ]; for test in test_cases { let link = format!( "{protocol}://{user}:{password}@{replicaset}/{database}", protocol = test.protocol, user = "test-public", password = "qhZbjRyvLjJvk5VZ", replicaset = test.url, database = test.database, ); let client_options = ClientOptions::parse(&link).unwrap(); let client = Client::with_options(client_options).unwrap(); println!("getting db..."); let db = client.database(test.database); println!("getting collection..."); let collection = db.collection(test.collection); // Query the documents in the collection with a filter and an option. let filter = doc! { "author": "George Orwell" }; let find_options = FindOptions::builder().sort(doc! { "title": 1 }).build(); let cursor = collection.find(filter, find_options); println!("got reply"); match cursor { Ok(_) => println!("*** PASS *** Got collection cursor"), Err(err) => println!("*** FAIL *** Error on collection cursor (error: {:?})", err), } } }
Cargo.toml:
Unable to find source-code formatter for language: toml. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
[package] name = "playground" version = "0.1.0" edition = "2018" [dependencies] mongodb = "0.9" bson = "0.14" serde = "1.0" serde_derive = "1.0" serde_json = "1.0"
Who I run it with `cargo run`, I get the following output:
getting db... getting collection... got reply *** PASS *** Got collection cursor getting db... getting collection... got reply *** FAIL *** Error on collection cursor (error: Error { kind: ServerSelectionError { message: "timed out while trying to select server" } }) getting db... getting collection... got reply *** FAIL *** Error on collection cursor (error: Error { kind: ServerSelectionError { message: "timed out while trying to select server" } })
- duplicates
-
RUST-272 Unable to connect to Atlas paid tier below 4.2
- Closed