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
27
28
use mongodb::{
bson::{doc, Document},
error::Result,
options::FindOptions, Cursor,
};
use serde::de::DeserializeOwned;
use crate::Collection;
impl<T: DeserializeOwned + Unpin + Send + Sync> Collection<T> {
pub async fn most_recent_by_cursor(
&self,
field: &str,
num_items: i64,
offset: u64,
filter: impl Into<Option<Document>>,
projection: impl Into<Option<Document>>,
) -> Result<Cursor<T>> {
let find_options = FindOptions::builder()
.sort(doc! { field: -1 })
.skip(offset)
.limit(num_items)
.projection(projection)
.build();
let cursor = self.collection.find(filter, find_options).await?;
Ok(cursor)
}
}