Hi.. I'm just learning about the Mongodb driver for Rust. I'm used to mongodb before, and I often use aggregation framework from mongodb to execute complex queries.
Unfortunately, I can't find any example for its implementation from web nor the driver's documentation. this is the best explanation that the driver give :
/// Runs an aggregation operation.
///
/// See the documentation [here](https://docs.mongodb.com/manual/aggregation/) for more
/// information on aggregations.
pub async fn aggregate(
&self,
pipeline: impl IntoIterator<Item = Document>,
options: impl Into<Option<AggregateOptions>>,
) -> Result<Cursor> {
let mut options = options.into();
resolve_options!(
self,
options,
[read_concern, write_concern, selection_criteria]
);
let aggregate = Aggregate::new(self.namespace(), pipeline, options);
let client = self.client();
client
.execute_cursor_operation(aggregate)
.await
.map(|(spec, session)| Cursor::new(client.clone(), spec, session))
}
AFAIK, the impl IntoIterator<Item = Document>
line in pipelines
field means that it only accepts an array vec<>
that implements IntoIterator
. I have no idea what the rest of the codes means.
Would someone be kind enough to give us an example for pipelines
and options
field ?