Update matching array elements with named filters.
Section: Arrays and positional updates
Target specific nested elements with arrayFilters
javascript
javascript
db.orders.updateOne(
{ _id: 1 },
{ $set: { "items.$[line].discounted": true } },
{ arrayFilters: [{ "line.qty": { $gte: 5 } }] }
)Explanation
`arrayFilters` are powerful for targeted nested updates without rewriting the whole array.
Learn the surrounding workflow
Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.
Related commands
Same sheet · prioritizing Arrays and positional updates