1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
use futures::stream::TryStreamExt;
use mongodb::{error::Result, options::FindOptions};
use serde::de::DeserializeOwned;

use crate::Collection;

impl<T: DeserializeOwned + Unpin + Send + Sync> Collection<T> {
    pub async fn get_some(&self, find_options: Option<FindOptions>) -> Result<Vec<T>> {
        let mut cursor = self.collection.find(None, find_options).await?;
        let mut items = Vec::new();
        while let Some(item) = cursor.try_next().await? {
            items.push(item);
        }
        Ok(items)
    }
}