Use the positional `$` operator.
Section: Arrays and positional updates
Update the first matching array element
javascript
javascript
db.orders.updateOne({ _id: 1, "items.sku": "A100" }, { $set: { "items.$.qty": 3 } })Explanation
The positional operator targets the first matched array element in the query.
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