Skip to content

Commit

Permalink
respect the "appName" field in MONGODB_URI
Browse files Browse the repository at this point in the history
  • Loading branch information
whisperpine committed Mar 10, 2024
1 parent aa3c728 commit edc17fb
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "axum_demo"
version = "0.5.2"
version = "0.5.3"
edition = "2021"
authors = ["Yusong Lai <yusong.lai@icloud.com>"]
license = "MIT OR Apache-2.0"
Expand Down
8 changes: 5 additions & 3 deletions src/mongo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ static DB_NAME: Lazy<String> = Lazy::new(|| match std::env::var(ENV_DB_NAME) {
}
});

/// MongoDB Uri.
/// MongoDB connection string.
static MONGODB_URI: Lazy<String> = Lazy::new(|| match std::env::var(ENV_MONGODB_URI) {
Ok(value) => {
tracing::info!("{}={}", ENV_MONGODB_URI, value);
Expand All @@ -49,7 +49,7 @@ pub async fn log_mongo() -> Result<Json<Vec<String>>, AppError> {
Ok(Json(texts))
}

/// Connect to mongodb and get client handle
/// Connect to mongodb and get client handle.
async fn connect() -> Result<Client> {
use std::time::Duration;
use tokio::time::timeout;
Expand All @@ -70,7 +70,9 @@ async fn connect() -> Result<Client> {
};

// Manually set an option.
client_options.app_name = Some("axum-demo".to_owned());
client_options
.app_name
.get_or_insert(crate::CRATE_NAME.to_owned());

// Get a handle to the deployment.
let client = Client::with_options(client_options)?;
Expand Down

0 comments on commit edc17fb

Please sign in to comment.