I am just trying to establish a connection with MongoDB Atlas in Rust for learning purposes
Here is what I am getting
thread 'tokio-runtime-worker' panicked at srcdb_connection.rs:33:14:
error connecting to database: Error { kind: InvalidArgument { message: "connection string contains no scheme" }, labels: {}, wire_version: None, source: None }
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Here is the Code I am using
dotenv().ok();
let uri = match env::var("MONGOURI") {
Ok(v) => v.to_string(),
Err(_) => format!("Error loading env variable"),
};
let client = Client::with_uri_str(uri)
.await
.expect("error connecting to database");
let col = client.database("mydb").collection("mycol");
Here is what I am using in .env
MONGOURI=mongodb+srv://username:[email protected]/mydb?retryWrites=true&w=majority
Please let me know, where I’m doing mistake
New contributor
mmmmm is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.