Articles → MONGODB → Arrayfilters Feature In Mongodb

Arrayfilters Feature In Mongodb






Purpose





Example




Picture showing the sample documents in mongodb




db.mycollection.updateOne(
   { "_id": 1 },
   {
     $set: { "scores.$[element].score": 95 }
   },
   {
     arrayFilters: [ { "element.type": "quiz", "element.score": 90 } ]
   }
)




Picture showing executing the updateone using the arrayfilters



Output


Picture showing the result after executing the updateone using the arrayfilters



Posted By  -  Karan Gupta
 
Posted On  -  Friday, March 29, 2024

Query/Feedback


Your Email Id
 
Subject
 
Query/FeedbackCharacters remaining 250