{"record":{"id":"e4ebfae76428908c","repo":"moghtech/komodo","slug":"config-database-not-configured-correctly-must-p","errorCode":null,"errorMessage":"'config.database' not configured correctly. must pass either 'config.database.uri', or 'config.database.address' + 'config.database.username' + 'config.database.password'","messagePattern":"'config\\.database' not configured correctly\\. must pass either 'config\\.database\\.uri', or 'config\\.database\\.address' \\+ 'config\\.database\\.username' \\+ 'config\\.database\\.password'","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"critical","filePath":"lib/database/src/lib.rs","lineNumber":231,"sourceCode":"    !uri.is_empty(),\n    !address.is_empty(),\n    !username.is_empty(),\n    !password.is_empty(),\n  ) {\n    (true, _, _, _) => {\n      client = client.uri(uri);\n    }\n    (_, true, true, true) => {\n      client = client\n        .address(address)\n        .username(username)\n        .password(password);\n    }\n    (_, true, _, _) => {\n      client = client.address(address);\n    }\n    _ => {\n      return Err(anyhow!(\n        \"'config.database' not configured correctly. must pass either 'config.database.uri', or 'config.database.address' + 'config.database.username' + 'config.database.password'\"\n      ));\n    }\n  }\n\n  let client = client\n    .build()\n    .await\n    .context(\"Failed to initialize database connection.\")?;\n\n  Ok(client.database(db_name))\n}\n\nasync fn resource_collection<T: Send + Sync>(\n  db: &Database,\n  collection_name: &str,\n) -> anyhow::Result<Collection<T>> {\n  let coll = db.collection::<T>(collection_name);","sourceCodeStart":213,"sourceCodeEnd":249,"githubUrl":"https://github.com/moghtech/komodo/blob/780ac68b992094a9fccd5fffb760e0c84fd3c3d1/lib/database/src/lib.rs#L213-L249","documentation":"The database init() builds a mongodb Client options object from config.database and validates that exactly one of the accepted credential shapes is present: a full URI, or an address together with username+password. Any other combination falls to the catch-all arm and aborts initialization with this error, because the driver cannot construct valid connection options.","triggerScenarios":"Calling Database::new when config.database has neither uri, nor address, nor the username/password pair; e.g. only address without username/password, or username/password without address, or an entirely empty database section.","commonSituations":"Partial config files where only database.address was set; env-var-driven configs where some DB_* variables weren't exported; switching from URI-based to split-credential config and forgetting a field; default/example configs left unedited.","solutions":["Set config.database.uri to a valid mongodb:// connection string (simplest path)","Or set address together with BOTH username and password in config.database","Log the resolved config keys (without secrets) to see which fields are missing","Validate the database config at application startup before calling new()"],"exampleFix":"// before (config)\n[database]\naddress = \"localhost:27017\"\n// after (config)\n[database]\nuri = \"mongodb://localhost:27017\"\n# or address + username + password together","handlingStrategy":"validation","validationCode":"fn validate_db_config(cfg: &DatabaseConfig) -> Result<(), String> {\n  if cfg.uri.is_some() { return Ok(()); }\n  if cfg.address.is_some() && cfg.username.is_some() && cfg.password.is_some() { return Ok(()); }\n  Err(\"config.database needs 'uri' or 'address' + 'username' + 'password'\".into())\n}","typeGuard":null,"tryCatchPattern":"match Database::new(&config).await {\n  Err(e) if e.to_string().contains(\"'config.database' not configured correctly\") => {\n    panic!(\"database section misconfigured: {}\", e);\n  }\n  other => other,\n}","preventionTips":["Fail fast at startup by validating the database config before use","Keep all four fields (or just uri) sourced from env/config together","Add an integration test that constructs Database from your production config shape","Never commit partial example configs as defaults"],"tags":["database","configuration","mongodb","missing-config"],"backgroundTag":"missing-required-config-field","analyzedSha":"780ac68b992094a9fccd5fffb760e0c84fd3c3d1","analyzedAt":"2026-09-08T10:02:44.861Z","contentChangedAt":"2026-09-08T10:02:44.861Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}