1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
use actix_web::web;
use anyhow::Result;
use mongodb::{Client, Collection};
use std::sync::Mutex;

pub const DATABASE: &str = "fplus-db";

pub async fn get_collection<T>(
    state: web::Data<Mutex<Client>>,
    collection_name: &str,
) -> Result<Collection<T>> {
    let col: Collection<T> = state
        .lock()
        .unwrap()
        .database(DATABASE)
        .collection(collection_name);
    Ok(col)
}