feat(db): add MONGO_PORT environment variable

This commit is contained in:
Franek 2024-05-15 16:34:21 +02:00
parent 47973a6e89
commit 9f6413ccdf
No known key found for this signature in database
GPG Key ID: 0329F871B2079351

View File

@ -8,9 +8,13 @@ pub async fn create_connection() -> Client {
let username = var("MONGO_USERNAME").unwrap();
let password = var("MONGO_PASSWORD").unwrap();
let host = var("MONGO_HOST").unwrap();
let port: u32 = var("MONGO_PORT")
.unwrap_or("80".to_string())
.parse()
.expect("invalid MONGO_PORT");
let mut client_options = ClientOptions::parse(
format!("mongodb+srv://{username}:{password}@{host}/?retryWrites=true&w=majority")
format!("mongodb+srv://{username}:{password}@{host}:{port}/?retryWrites=true&w=majority")
).await.unwrap();
let server_api = ServerApi::builder().version(ServerApiVersion::V1).build();