macro_rules! pipeline { ($($tt:tt)*) => { ... }; }
Expand description
Helper to build aggregation pipelines.
Return a Vec
Example
use mongodm::prelude::*;
struct User {
_id: ObjectId,
name: String,
}
struct Session {
user_id: ObjectId,
}
// Using the pipeline! helper :
let a = pipeline! [
Match: { f!(name in User): "John" },
Lookup {
From: "sessions",
As: "sessions",
LocalField: f!(_id in User),
ForeignField: f!(user_id in Session),
}
];
// Without pipeline helper :
let b = vec![
doc! { "$match": { f!(name in User): "John" } },
Lookup {
From: "sessions",
As: "sessions",
LocalField: f!(_id in User),
ForeignField: f!(user_id in Session),
}.into(),
];
// Without any helpers :
let c = vec![
doc! { "$match": { "name": "John" } },
doc! { "$lookup": {
"from": "sessions",
"as": "sessions",
"localField": "_id",
"foreignField": "user_id",
} },
];
// Generated pipelines are identicals
assert_eq!(a, b);
assert_eq!(a, c);