$ positional operator

Reference type:Cheat sheetFormat:Syntax + example + use case

Reference group: Array update operators

What it does

Updates the first array element matched by the query.

Syntax

array.$.field

Use case

Update a matched embedded element.

$ positional operator: practical example
db.orders.updateOne({ _id: orderId, "items.sku": "KB-1" }, { $set: { "items.$.status": "packed" } })
💡 Explanation Updates the first array element matched by the query. When to use it Update a matched embedded element.
Key Takeaways
  • Updates the first array element matched by the query.
  • Typical use: Update a matched embedded element.