$filter
Reference group: Array aggregation expressions
What it does
Keeps elements satisfying a condition and preserves relative order.
Syntax
{$filter: { input, as?, cond, limit? }}
Use case
Filter arrays without unwinding.
$filter: practical example
{ $project: { passing: { $filter: { input: "$scores", as: "s", cond: { $gte: ["$$s", 70] } } } } }💡 Explanation
Keeps elements satisfying a condition and preserves relative order.
When to use it
Filter arrays without unwinding.
Key Takeaways
- Keeps elements satisfying a condition and preserves relative order.
- Typical use: Filter arrays without unwinding.