Articles → MONGODB → $Filter Aggregator Operator In Mongodb

$Filter Aggregator Operator In Mongodb






Purpose





Syntax


{
  $filter: {
    input: <array>,
    as: <variable>,
    cond: <condition>
  }
}



Example




Picture showing the sample document collection




db.filterdemo.aggregate([
  {
    $project: {
      name: 1,
      highScores: {
        $filter: {
          input: "$scores",
          as: "score",
          cond: { $lt: ["$$score", 70] }
        }
      }
    }
  }
])



Output


Picture showing the output of filter aggregator operator in mongodb



Posted By  -  Karan Gupta
 
Posted On  -  Friday, June 7, 2024

Query/Feedback


Your Email Id
 
Subject
 
Query/FeedbackCharacters remaining 250