1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
use mongodb::{Client, options::ClientOptions};
use log::{log_enabled, info, Level};
pub async fn connect<T>(mongodb_uri: T) -> Result<Client, Box<dyn std::error::Error>>
where T: core::fmt::Display {
let mongodb_uri = format!("{}", mongodb_uri);
let client_options = ClientOptions::parse(&mongodb_uri).await?;
let client = Client::with_options(client_options)?;
if log_enabled!(Level::Info) {
info!("mongodb connected");
}
Ok(client)
}