mongodb-helper 0.1.6

A mongodb helper
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
use bson::{DecoderError, Document};
use mongodb::options::CountOptions;

impl super::Database {
    pub fn count(
        &self,
        collection: &str,
        filter: Option<Document>,
        options: Option<CountOptions>,
    ) -> Result<i64, DecoderError> {
        let collection = self.db.collection(&String::from(collection));
        match collection.count_documents(filter, options) {
            Ok(r) => return Ok(r),
            Err(e) => return Err(DecoderError::Unknown(e.to_string())),
        }
    }
}