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
26
use mongodb::Client;
use mongodb::error::Error;
use crate::config::mongodb_config::MongoDbConfig;
pub struct MongoDbConnectionManager {
client: Client,
}
impl MongoDbConnectionManager {
pub fn try_new(mongodb_config: MongoDbConfig) -> Result<MongoDbConnectionManager, Error> {
let client = match Client::with_options(mongodb_config.client_options()) {
Ok(client) => client,
Err(error) => {
return Err(error);
}
};
Ok(MongoDbConnectionManager { client })
}
pub fn client(&self) -> &Client {
&self.client
}
}