Articles → MONGODB → $Filter Aggregator Operator In Mongodb
$Filter Aggregator Operator In Mongodb
Purpose
Syntax
{
$filter: {
input: <array>,
as: <variable>,
cond: <condition>
}
}
Example
db.filterdemo.aggregate([
{
$project: {
name: 1,
highScores: {
$filter: {
input: "$scores",
as: "score",
cond: { $lt: ["$$score", 70] }
}
}
}
}
])
Output
Posted By - | Karan Gupta |
|
Posted On - | Friday, June 7, 2024 |